> 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/basic-operations/basics/daynight-themes.md).

# Day and night themes in Xamarin

Learn how to implement a dark theme in Xamarin.Android using the DayNight theme in AppCompat. Switch between light and dark themes in your activity with this step-by-step tutorial. The Apryse Xamarin

{% 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.

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

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

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

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*

{% tabs %}
{% tab title="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 %}
{% endtab %}
{% endtabs %}

*res/values-night/styles.xml*

{% tabs %}
{% tab title="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 %}
{% 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 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/xamarin/basic-operations/basics/daynight-themes.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.
