Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

Some times primaryColor and accentColor are not used #37

Open
tcqq opened this issue Jun 10, 2018 · 9 comments
Open

Some times primaryColor and accentColor are not used #37

tcqq opened this issue Jun 10, 2018 · 9 comments

Comments

@tcqq
Copy link

tcqq commented Jun 10, 2018

@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)
@garretyoder
Copy link
Owner

Post your custom theme.

@tcqq
Copy link
Author

tcqq commented Jun 11, 2018

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

@garretyoder
Copy link
Owner

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

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

@tcqq
Copy link
Author

tcqq commented Jun 12, 2018

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

@garretyoder
Copy link
Owner

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
Copy link
Author

tcqq commented Jun 12, 2018

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>

@garretyoder
Copy link
Owner

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
Copy link
Author

tcqq commented Jun 17, 2018

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>

@garretyoder
Copy link
Owner

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants