Color modes

There are a few themes which can be adjusted to change the output color mode.

Day and night themes in Android

Apryse Docs Image

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.

1int mode = isNight ? AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO;
2getDelegate().setLocalNightMode(mode);
3recreate();

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

For example, in our DocumentActivity, we change the device UI night mode when the PDFViewCtrl's color mode is updated:

1@Override
2public boolean onColorModeUpdated() {
3 boolean isDarkMode = PdfViewCtrlSettingsManager.isDarkMode(this);
4 if (isDeviceNightMode() != isDarkMode) {
5 getDelegate().setLocalNightMode(isDarkMode
6 ? AppCompatDelegate.MODE_NIGHT_YES
7 : AppCompatDelegate.MODE_NIGHT_NO);
8 recreate();
9 return true;
10 }
11 return false;
12}
13
14public boolean isDeviceNightMode() {
15 int currentNightMode = getResources().getConfiguration().uiMode
16 & Configuration.UI_MODE_NIGHT_MASK;
17 return currentNightMode == Configuration.UI_MODE_NIGHT_YES;
18}

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

Java

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

XML

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

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales