开发者

Cannot retrieve a color from colors.xml through a custom resource?

开发者 https://www.devze.com 2023-01-14 05:52 出处:网络
I\'m going through an Android tutorial and I\'m trying to access a color I\'ve defined in colors.xml <color name = \"my_background\">#3500ffff</color>

I'm going through an Android tutorial and I'm trying to access a color I've defined in colors.xml

<color name = "my_background">#3500ffff</color>

Then I'm trying to access this color by name:

Paint background = new Paint();
background.setColor(getResources().getColor(R.color.my_background));

but it doesn't recognize my_background as a resource. If I let the suggest开发者_如何学Goions come up, only a bunch of pre-defined colors pop up that are unrelated. Any ideas? It doesn't make sense for me, I see almost the exact same thing from the developer documentation and another site, but it doesn't work for me.


I found that the problem was animport android.R somehow made it's way into the top of my code without me noticing. I removed that and the problem was solved.

0

精彩评论

暂无评论...
验证码 换一张
取 消