android - Custom color kit by Style -


how create custom colors kit themes?

  • in styles.xml

     <style name="dark" parent="@style/theme.appcompat">      <item name="bluestyled">#229</item>  </style> 
  • in values-v21/colors.xml

    <color name="bluestyled">?bluestyled</color> 

but app crashes when try set color, e.g.: android:background="@color/bluestyled"

first, define colors in res/values/colors.xml:

<color name="dark_color">#229</color> <color name="light_color">#6161ff</color> 

create attribute you're gonna use color in /res/attrs.xml:

<resources>     <attr name="blue_styled" format="reference"/> </resources> 

define items in styles same name name of attribute , desired colors values:

<style name="dark" parent="@style/theme.appcompat">      <item name="blue_styled">@color/dark_color</item> </style>  <style name="light" parent="@style/theme.appcompat.light">      <item name="blue_styled">@color/light_color</item> </style> 

use attribute background:

android:background="?attr/blue_styled" 

the attribute should resolved appropriate color based on theme.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -