Some test text!

menu
search
Themeskeyboard_arrow_down

Themes

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

Day and Night themes

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.

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

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:

@Override
public boolean onColorModeUpdated() {
    boolean isDarkMode = PdfViewCtrlSettingsManager.isDarkMode(this);
        if (isDeviceNightMode() != isDarkMode) {
            getDelegate().setLocalNightMode(isDarkMode
                ? AppCompatDelegate.MODE_NIGHT_YES
                : AppCompatDelegate.MODE_NIGHT_NO);
        recreate();
        return true;
    }
    return false;
}

public boolean isDeviceNightMode() {
    int currentNightMode = getResources().getConfiguration().uiMode
        & Configuration.UI_MODE_NIGHT_MASK;
    return currentNightMode == Configuration.UI_MODE_NIGHT_YES;
}

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="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
        <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="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
    <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: Support

close

Free Trial

Get unlimited trial usage of PDFTron SDK to bring accurate, reliable, and fast document processing capabilities to any application or workflow.

Select a platform to get started with your free trial.

Unlimited usage. No email address required.

PDFTron Receives USD$71 Million Growth Investment Led By Silversmith Capital Partners

Learn More
close