> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/android/annotation/tool-style.md).

# Customize default annotation tool style in Android

Learn how to customize default styles for annotations in your app using ToolManager. Override existing tool styles and create custom tool styles for a personalized touch. Click to find out more! The A

## Programmatically

When creating a new annotation, the initial properties (such as line thickness, fill color, opacity, etc.) are set to the last value that the user selected for an annotation of that type. For example, if the user changes an ellipse annotation's stroke color from green to red, the next ellipse annotation that the user creates would have a stroke color of red. These default properties are saved in the app's [SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences).

These default properties can be changed programmatically and will take effect the next time when the annotation is created.

For example, to change style properties of a rectangle:

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
var tool = (RectCreate) toolManager.createTool(ToolManager.ToolMode.RectCreate, null);
tool.SetupAnnotProperty(
    Color.Green,
    ToolStyleConfig.Instance.GetCustomOpacity(pdfViewCtrl.Context, (int)Annot.Type.e_Square, ""),
    ToolStyleConfig.Instance.GetCustomThickness(pdfViewCtrl.Context, (int)Annot.Type.e_Square, ""),
    Color.RED,
    null, null
);
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
RectCreate tool = (RectCreate) toolManager.createTool(ToolManager.ToolMode.RECT_CREATE, null);
tool.setupAnnotProperty(
    Color.GREEN,
    ToolStyleConfig.getInstance().getCustomOpacity(pdfViewCtrl.getContext(), Annot.e_Square, ""),
    ToolStyleConfig.getInstance().getCustomThickness(pdfViewCtrl.getContext(), Annot.e_Square, ""),
    Color.RED,
    null,
    null
);
```

{% endcode %}
{% endtab %}

{% tab title="Kotlin" %}
{% code lineNumbers="true" %}

```kotlin
val tool = toolManager.createTool(ToolManager.ToolMode.RECT_CREATE, null) as RectCreate
tool.setupAnnotProperty(
  Color.GREEN,
  ToolStyleConfig.getInstance().getCustomOpacity(pdfViewCtrl.getContext(), Annot.e_Square, ""),
  ToolStyleConfig.getInstance().getCustomThickness(pdfViewCtrl.getContext(), Annot.e_Square, ""),
  Color.RED,
  null, null
)
```

{% endcode %}
{% endtab %}
{% endtabs %}

where `toolManager` is an instance of [`ToolManager`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/tools/ToolManager.html).

A table for annotation type and tool mode mapping can be found here: annotation and its creation tool.

## XML attributes

Each annotation has a default style that is defined by its creation tool. For example, when you create a [`Square`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/annots/Square.html) annotation using the [`RectCreate`](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/tools/RectCreate.html) tool for the first time, the default behavior to draw a rectangle with a red border and a transparent fill color. These default colors can changed through XML attributes.

{% hint style="info" %}
However the effect will only take place when the app is first loaded.
{% endhint %}

### Set a tool's default style

1. Add a style to your `styles.xml` file. For details on supported style attributes, see [Tool Style Attributes](#tool-style-attributes).

{% tabs %}
{% tab title="XML" %}
{% code lineNumbers="true" %}

```xml
<style name="ShapeProperty"> 
    <!-- border color --> 
    <item name="annot_color">@android:color/white</item> 
    <!-- fill color --> 
    <item name="annot_fill_color">@android:color/white</item> 
    <!-- thickness --> 
    <item name="annot_thickness">1.0</item> 
    <!-- opacity --> 
    <item name="annot_opacity">1.0</item> 
</style>
```

{% endcode %}
{% endtab %}
{% endtabs %}

2. Add the style resource to [`ToolStyleConfig`](https://sdk.apryse.com/api/xamarinandroid/tools/api/pdftron.PDF.Config.ToolStyleConfig.html) by calling [`addDefaultStyleMap(int, int styleRes)`](https://sdk.apryse.com/api/xamarinandroid/tools/api/pdftron.PDF.Config.ToolStyleConfig.html#pdftron_PDF_Config_ToolStyleConfig_AddDefaultStyleMap_System_Int32_System_Int32_)

{% hint style="info" %}
The first parameter of addDefaultStyleMap is an annotation type. You can determine the annotation type from the creator tool by referring to the [Table of annotations and its creation tool.](/android/annotation/tools.md#annotation-and-its-creation-tool)
{% endhint %}

{% tabs %}
{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
// Add the R.style.ShapeProperty to RectCreate tool. 
// Since the RectCreate tool creates a Square annotation, the annotation type of a Square 
// annotation is Annot.e_Square 
ToolStyleConfig.getInstance().addDefaultStyleMap(Annot.e_Square, R.style.ShapeProperty);
```

{% endcode %}
{% endtab %}

{% tab title="Kotlin" %}
{% code lineNumbers="true" %}

```kotlin
 // Add the R.style.ShapeProperty to RectCreate tool.
    // Since the RectCreate tool creates a Square annotation, the annotation type of a Square
    // annotation is Annot.e_Square
    ToolStyleConfig.getInstance().addDefaultStyleMap(Annot.e_Square, R.style.ShapeProperty)
```

{% endcode %}
{% endtab %}

{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
    // Add the R.style.ShapeProperty to RectCreate tool.
    // Since the RectCreate tool creates a Square annotation, the annotation type of a Square
    // annotation is Annot.e_Square
    ToolStyleConfig.Instance.AddDefaultStyleMap((int) Annot.Type.e_Square, Resource.Style.ShapeProperty);
```

{% endcode %}
{% endtab %}
{% endtabs %}

### Override an existing tool's default style

You can also override existing tool's default styles:

1. Identify the tool whose style you want to override by consulting the following table.

| Tool                                                                                                                       | Style attribute resource           | Default style resource          |
| -------------------------------------------------------------------------------------------------------------------------- | ---------------------------------- | ------------------------------- |
| [TextHighlightCreate](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/tools/TextHighlightCreate.html) | `R.attr.highlight_default_style`   | `R.style.HighlightPresetStyle1` |
| [TextUnderlineCreate](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/tools/TextUnderlineCreate.html) | `R.attr.underline_default_style`   | `R.style.TextMarkupStyle1`      |
| [TextStrikeoutCreate](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/tools/TextStrikeoutCreate.html) | `R.attr.strikeout_default_style`   | `R.style.TextMarkupStyle1`      |
| [TextSquigglyCreate](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/tools/TextSquigglyCreate.html)   | `R.attr.squiggly_default_style`    | `R.style.TextMarkupStyle1`      |
| [RectLinkCreate](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/tools/RectLinkCreate.html)           | `R.attr.link_default_style`        | `R.style.TextMarkupStyle1`      |
| [RulerCreate](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/tools/RulerCreate.html)                 | `R.attr.ruler_default_style`       | `R.style.RulerStyle1`           |
| [FreeTextCreate](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/tools/FreeTextCreate.html)           | `R.attr.free_text_default_style`   | `R.style.FreeTextPresetStyle1`  |
| [StickyNoteCreate](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/tools/StickyNoteCreate.html)       | `R.attr.sticky_note_default_style` | `R.style.AnnotPresetStyle1`     |
| [Signature](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/tools/Signature.html)                     | `R.attr.signature_default_style`   | `R.style.SignaturePresetStyle1` |
| [FreehandCreate](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/tools/FreehandCreate.html)           | `R.attr.freehand_default_style`    | `R.style.AnnotPresetStyle4`     |
| Other                                                                                                                      | `R.attr.other_default_style`       | `R.style.AnnotPresetStyle4`     |

1. Create a custom tool style that inherits from the default tool style resource in `styles.xml`. For example, if you want to override the `FreehandCreate` tool style, your custom tool style should inherit from `AnnotPresetStyle4`.

{% tabs %}
{% tab title="XML" %}
{% code lineNumbers="true" %}

```xml
<style name="CustomizedToolStyle" parent="AnnotPresetStyle4"> <item name="annot_color">@android:color/white</item> </style>
```

{% endcode %}
{% endtab %}
{% endtabs %}

{% hint style="info" %}
To learn about style inheritance, see: [Defining styles and inheritance](https://developer.android.com/guide/topics/ui/look-and-feel/themes.html#Inheritance).
{% endhint %}

1. In your application theme, set your custom tool style (`CustomizedToolStyle`) to the tool style attribute that corresponds to the tool style you wish to override. For example, if you want to the override `FreehandCreate` tool style, set `CustomizedToolStyle` to the attribute `freehand_default_style`.

{% tabs %}
{% tab title="XML" %}
{% code lineNumbers="true" %}

```xml
<style name="PDFTronAppTheme" parent="PDFTronAppThemeBase"> <item name="freehand_default_style">@style/CustomizedToolStyle</item> </style>
```

{% endcode %}
{% endtab %}
{% endtabs %}

{% hint style="info" %}
To learn about applying custom themes to your application, see: [Applying a Theme to an Activity or Application](https://developer.android.com/guide/topics/ui/look-and-feel/themes.html#ApplyATheme).
{% endhint %}

## Tool style attributes

\####`annot_color` Annotation color. For annotations that have an [`annot_fill_color`](https://docs.apryse.com), it represents stroke color.

format: color

\####`annot_text_color` Annotation text color. Used for [FreeText](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/annots/FreeText.html) annotations.

format: color

#### `annot_fill_color`

Annotation fill color. Used for annotations that have fill colors, including [Square](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/annots/Square.html), [Circle](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/annots/Square.html), and [FreeText](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/annots/FreeText.html).

format: color

#### `annot_font_size`

Annotation font size. Used for [FreeText](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/annots/FreeText.html) annotations.

format: float

#### `annot_text_size_max`

Represents a [FreeText](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/annots/FreeText.html) annotation's maximum font size.

format: float

#### `annot_text_size_min`

Represents a [FreeText](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/annots/FreeText.html) annotation's minimum font size.

format: float

#### `annot_thickness`

Annotation thickness for border style

format: float

#### `annot_thickness_max`

Annotation maximum thickness

format: float

#### `annot_thickness_min`

Annotation minimum thickness

format: float

#### `annot_font`

Annotation font. Used for [FreeText](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/annots/FreeText.html) annotations.

format: string

#### `annot_opacity`

Annotation opacity

format: float

#### `annot_icon`

Annotation icon. Used for [Text](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/annots/Text.html) annotations.

format: string


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/android/annotation/tool-style.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
