garretyoder / Colorful

Android runtime theme library
Apache License 2.0
2.13k stars 193 forks source link

Disabled override how to use light/dark theme #33

Closed tcqq closed 6 years ago

tcqq commented 6 years ago

@garretyoder Dark/Light themeing will not work when override is disable, I try using "setCustomThemeOverride" to set it in style , when I changed Light to the Dark theme, but it will not change immediately, Only change after restarting the app. What did i do wrong? How should I correct it?

Code

Activity.java

        Colorful().edit()
                .setCustomThemeOverride(darkTheme ? R.style.AppThemeDark: R.style.AppTheme)
                .apply(getContext(), () -> {
                    recreate();
                    return null;
                });

BaseActivity.java

ColorfulKt.Colorful().apply(this, false, true);

Style.xml

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    </style>

    <style name="AppThemeDark" parent="Theme.AppCompat.NoActionBar">
    </style>
garretyoder commented 6 years ago

This is explained in the readme.

The override value will control whether Colorful overrides your activitie's existing base theme, or merely sets primary and accent colors. Note: dark/light themeing will not work when override is disabled