背景问题的风格和主题 [英] background issue with styles and themes

查看:135
本文介绍了背景问题的风格和主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ATTRS我有

<attr name="bzz" format="color" />

然后在主题

<style name="mytheme" parent="android:Theme">
    <item name="bzz">@color/aaa</item>
</style>

和在code 这个伟大的工程

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);

我不明白是什么问题,我的逻辑是,我设置为BZZ参考色,这样应该可以正常工作,但它不会:) 它说,像 android.content.res.Resources $ NotFoundException:资源ID#0x7f010008 但我不明白的资源不能被发现的?

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 ?

我相信,颜色是有罪过,如果我直接设置它的伟大工程,是什么exacly是不正确链接的东西

I am sure that the color is there sins if I set it directly it works great, what exacly is the thing that is not linked correctly

感谢

推荐答案

您需要解决的 ATTR ,以获得相应的颜色的资源ID。然后,您可以设置的TextView 的背景资源,获得的资源ID。

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.

例如code:

TypedValue typedValue = new TypedValue();
getTheme().resolveAttribute(R.attr.bzz, typedValue, true);
tv.setBackgroundResource(typedValue.resourceId);

这篇关于背景问题的风格和主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆