覆盖color.xml文件中的颜色值 [英] Override color value in color.xml file

查看:104
本文介绍了覆盖color.xml文件中的颜色值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以覆盖color.xml文件中已经设置的颜色?例如-我将布局上的背景色设置为backgroundColor ="@ color/background" background的值=#000000

Is there a way to override a color that is already set in your color.xml file? For example - I set the background color on the layout to backgroundColor = "@color/background" The value of background = #000000

我可以在Java中覆盖背景的实际颜色,并将@ color/background设置为-#FFFFFF吗?

Can I override the actual color of background in Java and set the @color/background to say - #FFFFFF?

推荐答案

可能,但代价很高.@ color/background等效于R.color.background,其中R是您生成的类.在运行时,您可以使用反射以使字段可写,然后更改它们.我真的不相信它会按您的意愿工作.

It's possible, but rather costly. @color/background is equivalent to R.color.background, where R is your generated class. At runtime, you could use reflection to make the fields writable, then change them. I'm not really convinced it would work how you want.

一种不同的想法是使用主题您想要的颜色,可能会让用户在它们之间进行切换.这样可以使您的设计和逻辑分离.

A different idea would be to use themes for the various colors you want, possibly letting the user switch between them. That'd keep your design and logic separate.

这篇关于覆盖color.xml文件中的颜色值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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