in attrs I have
<attr name="bzz" format="color" />
then in theme
<style name="mytheme" parent="android:Theme">
<item name="bzz">@color/aaa</item>
</style>
and in the code this works great
tv.setBackgroundResource(R.color.aaa);
but when I do this it gives me an error
tv.setBackgroundResource(R.attr.bzz);
I do not understand what is the problem, my logic is that I set the bzz as reference to color so that should work fine, but it does not :)
it says like android.content.res.Resources$NotFoundException: Resource ID #0x7f010008
but I do not understand what resource can't be found ?
I am sure that the color is there sins if I set it dir开发者_高级运维ectly it works great, what exacly is the thing that is not linked correctly
Thanks
You need to resolve the attr
to get the corresponding color
's resource id. Then you can set the TextView
's background resource to the obtained resource id.
Example code:
TypedValue typedValue = new TypedValue();
getTheme().resolveAttribute(R.attr.bzz, typedValue, true);
tv.setBackgroundResource(typedValue.resourceId);
精彩评论