颜色资源ID返回错误值 [英] Colour resource ID returning wrong value

查看:80
本文介绍了颜色资源ID返回错误值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从的onCreate中色资源编程设置文本颜色和我得到一些奇怪的结果。

I am trying to set the text colour programatically from a colour resource during onCreate and am getting some wierd results.

我在定义颜色资源RES \\ colors.xml:

I have a colour resource defined in res\colors.xml:

<resources>

    <color name="wheelFill">#C0FFFFFF</color>

</resources>

我的活动,然后使用以下code检索的颜色:

my activity then uses the following code to retrieve the colour:

int WheelColour = getResources().getColor(R.color.wheelFill);

最后,我把它分配给一个油漆:

Finally I assign it to a Paint:

mBackgroundPaint.setColor(WheelColour);

当我运行我的应用程序的颜色不被设置一个我从线的getColor声称颜色值列表,必须以#开始日志信息。 名单是我的字符串资源之一的值,以便清楚的东西是越来越乱了那里。

When I run my application the colour does not get set an I get a log message from the getColor line claiming that "Color value 'List' must start with #". 'List' is the value of one of my string resources so clearly something is getting messed up there.

如果我绕过资源,并使用:

If I bypass the resource and use:

int WheelColour = Color.argb(0xC0, 0xFF, 0xFF, 0xFF);

一切正常,所以它是调用的getColor,但我看不出有什么不妥的地方。 (我试图明确使用这没有什么区别上下文)。

Everything works correctly so it has to be the getColor call but I can't see what's wrong with it. (I have tried explicitly using a context which made no difference).

有其他人遇到这样或成功地设法从颜色资源设置油漆颜色?

Has anybody else come across this or sucessfully managed to set paint colours from colour resources?

推荐答案

也许你的R.java得到搞砸了,不链接到正确的资源。清理项目,并刷新

maybe your R.java got messed up and isn't linking to the correct resource. clean the project and refresh

这篇关于颜色资源ID返回错误值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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