【问题标题】:It is possible to write the value of an xml attribute (attrs.xml) with java code?可以用java代码写一个xml属性(attrs.xml)的值吗?
【发布时间】:2016-08-15 21:00:15
【问题描述】:

拥有这个 attrs.xml 文件:

<resources>
    <attr name="customColorPrimary" format="color" value="#111111"/>
</resources>

是否可以用 java 代码为该颜色编写一个新值?

在官方文档中找不到怎么做...

【问题讨论】:

    标签: android android-attributes attrs.xml


    【解决方案1】:

    简短回答:不。

    长答案:您在代码中使用的所有resources 都编译为R 类的内容。每个resource(包括stringdimenlayoutstyleattr 等)都被编译为public staticfinal@987654331 的一些变体@ 值。这就是为什么你不能在运行时修改它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-04
      • 1970-01-01
      相关资源
      最近更新 更多