> 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/xamarin/guides/android/viewer/themes.md).

# Themes (Android)

Learn how to implement day and night themes in Android using Xamarin.Android. Customize page color modes and set different styles for device day/night modes. Enhance reading experience with special co

You can use preset themes or choose custom page color modes.

{% tabs %}
{% tab title="Night" %}

## Day and night themes in Android

{% hint style="info" %}
**This tutorial only applies to Xamarin.Android.**
{% endhint %}

![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-93e01e121b89132125d6d26eb6d773a0d396181c%2Fead9783185a817347c896967ee91c12ef8d8c82a-2200x2157.png?alt=media)

AppCompat has a new theme called `DayNight` since [Support Lib 23.2.0](https://android-developers.googleblog.com/2016/02/android-support-library-232.html). So, if your activity's theme extends from one of the DayNight variants then you can switch between dark theme and light theme in your activity as follows.

{% code lineNumbers="true" %}

```csharp
var mode = isNight ? AppCompatDelegate.ModeNightYes : AppCompatDelegate.ModeNightNo;
this.Delegate.SetLocalNightMode(mode);
Recreate();
```

{% endcode %}

As you can see, to take any effect for changing night mode the activity should be re-created.

You can also have different styles for device day/night modes by creating new resources for night. This involves adding a new directory to the resources folder, using the night qualifier, to re-define the resources. In the following example, primary colors and accent color are different in day and night mode:

*res/values/styles.xml*

{% code lineNumbers="true" %}

```xml
<style name="PDFTronAppTheme" parent="PDFTronAppThemeBase"> <item name="colorPrimary">@color/color_primary_day</item> <item name="colorPrimaryDark">@color/color_primary_dark_day</item> <item name="colorAccent">@color/color_accent_day</item> </style>
```

{% endcode %}

*res/values-night/styles.xml*

{% code lineNumbers="true" %}

```xml
<style name="PDFTronAppTheme" parent="PDFTronAppThemeBase"> <item name="colorPrimary">@color/color_primary_night</item> <item name="colorPrimaryDark">@color/color_primary_dark_night</item> <item name="colorAccent">@color/color_accent_night</item> </style>
```

{% endcode %}
{% endtab %}

{% tab title="Custom" %}

## Page color mode

[`PDFViewCtrl`](https://sdk.apryse.com/api/xamarinandroid/pdfnet/api/pdftron.PDF.PDFViewCtrl.html) has three special color modes: night mode, inverted color mode, and custom color mode. In night mode, colors are adjusted to improve reading at night, in inverted color mode, all colors are inverted, and in custom color mode, you can set a custom color for text and the background color.

![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-343375628c2dff8eebaa3c1a94bea5d0a9ff71ae%2F66f05a343d0341455b509a9282075128a28bd48a-1430x544.png?alt=media)

Color modes from left to right: normal color mode, inverted color mode, night mode and custom color mode.

## Set the color mode

To set the color mode:

1. Find the constant value of the color mode

| Color mode          | Constant value                                                                                                                                                              |
| ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Normal color mode   | [`PDFRasterizer.ColorPostProcessMode.e_postprocess_none`](https://sdk.apryse.com/api/xamarinandroid/pdfnet/api/pdftron.PDF.PDFRasterizer.ColorPostProcessMode.html)         |
| Night mode          | [`PDFRasterizer.ColorPostProcessMode.e_postprocess_night_mode`](https://sdk.apryse.com/api/xamarinandroid/pdfnet/api/pdftron.PDF.PDFRasterizer.ColorPostProcessMode.html)   |
| Inverted color mode | [`PDFRasterizer.ColorPostProcessMode.e_postprocess_invert`](https://sdk.apryse.com/api/xamarinandroid/pdfnet/api/pdftron.PDF.PDFRasterizer.ColorPostProcessMode.html)       |
| Custom color mode   | [`PDFRasterizer.ColorPostProcessMode.e_postprocess_gradient_map`](https://sdk.apryse.com/api/xamarinandroid/pdfnet/api/pdftron.PDF.PDFRasterizer.ColorPostProcessMode.html) |

1. Call `SetColorPostProcessMode`.
2. Optionally, set the `PDFViewCtrl` background color for the best visual result. You can set background color by calling `SetClientBackgroundColor` (Xamarin.Android) or `SetBackgroundColor` (Xamarin.iOS).For example, set the background color to black for night mode:

![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-e2fd299ceaf0f87ad2aecf8f82269abbfed10f62%2F11a67ce052a7a6199ddd8c12ea5f1144a758c901-392x292.png?alt=media)

{% code lineNumbers="true" %}

```csharp
// Xamarin.Android
mPdfViewCtrl.SetClientBackgroundColor(0, 0, 0, false);

// Xamarin.iOS
mPdfViewCtrl.SetBackgroundColor(0, 0, 0, false);
```

{% endcode %}

1. If you are using `postprocess_gradient_map`, call `PDFViewCtrl.SetColorPostProcessColors` to set the white and black points. For example, for a sepia effect, try:

{% code lineNumbers="true" %}

```csharp
// Xamarin.Android
var darkBrown = Android.Graphics.Color.Rgb(61, 38, 10);
var lightBrown = Android.Graphics.Color.Rgb(245, 224, 202);
mPdfViewCtrl.SetColorPostProcessColors(lightBrown, darkBrown);

// Xamarin.iOS
var darkBrown = new UIKit.UIColor(0.24f, 0.15f, 0.04f, 1.0f);
var lightBrown = new UIKit.UIColor(0.96f, 0.88f, 0.79f, 1.0f);
mPdfViewCtrl.SetColorPostProcessColors(lightBrown, darkBrown);
```

{% endcode %}

1. Update `PDFViewCtrl` to redraw the contents:Sample result when using `postprocess_gradient_map` and a light/dark brown for the white/black color:

{% code lineNumbers="true" %}

```csharp
mPdfViewCtrl.Update(true);
```

{% endcode %}

![](https://653871032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjsBtuYmcKhWOdM9VCg4%2Fuploads%2Fgit-blob-147581910216d35f3a25250590fcd193fc50dc02%2F763253aeabe683dda72a42172754b12942b3ec44-948x1228.png?alt=media)
{% endtab %}
{% endtabs %}


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.apryse.com/xamarin/guides/android/viewer/themes.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
