【发布时间】:2016-08-15 21:00:15
【问题描述】:
拥有这个 attrs.xml 文件:
<resources>
<attr name="customColorPrimary" format="color" value="#111111"/>
</resources>
是否可以用 java 代码为该颜色编写一个新值?
在官方文档中找不到怎么做...
【问题讨论】:
标签: android android-attributes attrs.xml
拥有这个 attrs.xml 文件:
<resources>
<attr name="customColorPrimary" format="color" value="#111111"/>
</resources>
是否可以用 java 代码为该颜色编写一个新值?
在官方文档中找不到怎么做...
【问题讨论】:
标签: android android-attributes attrs.xml
简短回答:不。
长答案:您在代码中使用的所有resources 都编译为R 类的内容。每个resource(包括string、dimen、layout、style、attr 等)都被编译为public staticfinal@987654331 的一些变体@ 值。这就是为什么你不能在运行时修改它。
【讨论】: