garretyoder/Colorful

Some times primaryColor and accentColor are not used

tcqq opened this issue · 9 comments

tcqq commented

@garretyoder I want to use "customTheme", because only in this way can I change textColorPrimary color, but now primaryColor and accentColor are not used, this may be misunderstood, but these two values are non-null.

    val defaults:Defaults = Defaults(
            primaryColor = ThemeColor.GREEN,
            accentColor = ThemeColor.BLUE,
            useDarkTheme = false,
            translucent = false,
            customTheme = R.style.AppTheme)
    initColorful(this, defaults)

Post your custom theme.

tcqq commented
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:textColorPrimary">@color/grey_900</item>
</style>

Remove color primary/primarydark/accent from your theme and leave just text color.

Don't re-set values Colorful is already setting.

tcqq commented

When I remove color primary/primarydark/accent from the theme, but now color of the interface are not using ThemeColor.GREEN and ThemeColor.BLUE, now color is the default color of "Theme.AppCompat.Light.NoActionBar".

Ah I see your problem.

Remove the parent item. When you're merging a style don't use a parent theme because then you will override all the values Colorful just set.

tcqq commented

When I remove the parent item, the default color is now correct. But when I dynamically change setCustomThemeOverride, the textColorPrimary color does not work.

Colorful().edit()
    .setPrimaryColor(ThemeColor.RED)
    .setAccentColor(ThemeColor.BLUE)
    .setDarkTheme(false)
    .setCustomThemeOverride(R.style.AppThemeNight)
     .apply(this) {
        recreate()
    }
<style name="AppThemeNight">
    <item name="android:textColorPrimary">#FFEB3B</item>
</style>

Hmm. This seems like just weirdness with Android's style engine. What happens if you use a custom base theme instead of a override? Note you'll need a parent theme to do the base theme. The order of operations for Colorful is

Base Theme -> Colorful Colors -> Custom Override

Latter overrides the former.

tcqq commented

After switching theme

tim 20180617155028

Before switching theme

tim 20180617155031

Code

Application.kt

        val defaults = Defaults(
                ThemeColor.GREEN,
                ThemeColor.BLUE,
                false,
                false,
                R.style.BaseTheme)
        initColorful(this, defaults)

MainActivity.kt

class MainActivity : CAppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        button_switch_theme.setOnClickListener {
            Colorful().edit()
                    .setCustomThemeOverride(R.style.CustomTheme)
                    .apply(this) {
                        recreate()
                    }
        }
    }
}

Style.xml

<resources>

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorSecondary">@color/colorSecondary</item>

        <item name="android:textColorPrimary">#D50000</item>
    </style>

    <style name="BaseTheme">
        <item name="android:textColorPrimary">#D50000</item>
    </style>

    <style name="CustomTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:textColorPrimary">#D50000</item>
    </style>

</resources>

I've been very busy and haven't gotten time to test this yet, but I plan on testing if I can reproduce this tonight.