What Does The "the Returned Color Will Be Styled For The Specified Context's Theme" Mean?
Solution 1:
From the docs for Resources
- int getColor (int id, Resources.Theme theme)
:
Returns a themed color integer associated with a particular resource ID. If the resource holds a complex ColorStateList, then the default color from the set is returned.
So the resource id can be more than just a simple color, it could point to something like this:
<selectorxmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:state_focused="true"android:color="@color/sample_focused" /><itemandroid:state_pressed="true"android:state_enabled="false"android:color="@color/sample_disabled_pressed" /><itemandroid:state_enabled="false"android:color="@color/sample_disabled_not_pressed" /><itemandroid:color="@color/sample_default" /></selector>
in which case the color returned would be @color/sample_default
.
But if you wanted to use attributes for the colors, something like this
<itemandroid:color="?attr/sample_default_color" />
you would need to access the attribute value within the theme in order to completely resolve the color value.
According to Alex Lockwood's blog post, these resources aren't actually attached to a theme, and if you call the old method with a color state list that uses attributes, an exception will be thrown. Before Marshmallow, you couldn't use attributes in color state lists due to this limitation.
Post a Comment for "What Does The "the Returned Color Will Be Styled For The Specified Context's Theme" Mean?"