Some test text!

Search
Hamburger Icon

Xamarin / Android

Themes (Android)

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

Day and night themes in Android

This tutorial only applies to Xamarin.Android.
Day-Night

AppCompat has a new theme called DayNight since Support Lib 23.2.0. 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.

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

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

<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>

res/values-night/styles.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>

Get the answers you need: Chat with us