So there I have a color defined as an attribute because it is dependent on the theme.
<attr name="primary_text_color" format="color"/>
It is defined in the theme as
<style name="BaseReferencesTheme" parent="Theme.AppCompat.NoActionBar">
<item name="primary_text_color">#ffffffff</item>
</style>
I'd like to wrap it with a real color resource.
<color name="selected_color_normal">?attr/primary_text_color</color>
And then read it from code
int resolvedColor = ContextCompat.getColor(context, R.color.selected_color_normal);
When I do this, I am getting an exception
android.content.res.Resources$NotFoundException: Resource ID #0x7f06010e type #0x2 is not valid
at android.content.res.Resources.getColor(Resources.java:955)
at android.content.Context.getColor(Context.java:588)
at android.support.v4.content.ContextCompat.getColor(ContextCompat.java:523)
There are a few modules here I work with:
attr_module
where the attributes are defined.theme_module
where the theme is defined and set to the applicationusage_module
which knows nothing about the theme, but does depend on the attr_module
.I know for sure that the theme is applied to the views in the usage_module
. All the dependencies are set correctly, when I do not try to programmatically read selected_color_normal
, but just applying the attribute - everything is working.
Thanks for any help!
For now I am considering this issue not solvable. Currently my approach is to use ?attr/primary_text_color
and R.attr.primary_text_color
everywhere possible.
I think, problem here is because primary_text_color
is attribute, and selected_color_normal
is color.
Try to make
<color name="selected_color_normal">#FFFFFFFF</color>
And then, in your style you can give primary_text_color
value of selected_color_normal
if needed:
<style name="BaseReferencesTheme" parent="Theme.AppCompat.NoActionBar">
<item name="primary_text_color">@color/selected_color_normal</item>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With