Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to override color attributes #30

Open
tcqq opened this issue Dec 2, 2018 · 1 comment
Open

Unable to override color attributes #30

tcqq opened this issue Dec 2, 2018 · 1 comment

Comments

@tcqq
Copy link

tcqq commented Dec 2, 2018

I want to overwrite the textColorPrimary color to red. When I change the color, the textColorPrimary in the Android Studio preview is red (the correct effect), but the effect of running the display is black, and the color of textColorPrimary has not changed. This problem also exists in the Colorful library. How can I fix this problem?

49334689-a7385380-f616-11e8-8578-feaafdab21b0
image
49334694-c505b880-f616-11e8-9796-b9b8c44beacc
tim 20181202094843

@jaredrummler
Copy link
Owner

If the theme has been modified, Cyanea will call setTheme with a Cyanea based style in Activity#onCreate. Unfortunately this will modify current styles that you might have set.

I will need to come up with a better alternative, but for now, you will have to create 4 styles and override getThemeResId in your activity. This way, you can specify which style Cyanea should use.

Example:

In res/values/styles.xml:

<style name="AppTheme.Light.DarkActionBar" parent="Theme.Cyanea.Light.DarkActionBar">
  <item name="android:textColorPrimary">@color/my_primary_text_color</item>
</style>

<style name="AppTheme.Light" parent="Theme.Cyanea.Light">
  <item name="android:textColorPrimary">@color/my_primary_text_color</item>
</style>

<style name="AppTheme.Dark" parent="Theme.Cyanea.Dark">
  <item name="android:textColorPrimary">@color/my_primary_text_color</item>
</style>

<style name="AppTheme.Dark.LightActionBar" parent="Theme.Cyanea.Dark.LightActionBar">
  <item name="android:textColorPrimary">@color/my_primary_text_color</item>
</style>

Then, in your activity:

class MainActivity : CyaneaAppCompatActivity() {

  /**
   * Get the correct style for Cyanea
   */
  @get:StyleRes
  private val actionBarTheme: Int
    get() = when (cyanea.baseTheme) {
      DARK ->
        if (cyanea.isActionBarLight)
          R.style.AppTheme_Dark_LightActionBar
        else
          R.style.AppTheme_Dark
      LIGHT ->
        if (cyanea.isActionBarDark)
          R.style.AppTheme_Light_DarkActionBar
        else
          R.style.AppTheme_Light
    }

  override fun getThemeResId(): Int = actionBarTheme

}

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

No branches or pull requests

2 participants