在为styable属性生成引用时,似乎在生成R.java文件时出现了问题。
人们会期望该字段的声明为final
但事实并非如此。怎么样?
RES /值/ attrs.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="MyTextView">
<attr name="typeface" format="string"/>
</declare-styleable>
</resources>
GEN / com。示例/ R.java
/**
<p>This symbol is the offset where the {@link com.example.R.attr#typeface}
attribute's value can be found in the {@link #MyTextView} array.
<p>Must be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character.
<p>This may also be a reference to a resource (in the form "<code>@[<i>package</i>: <i>type</i>:<i>name</i></code>") or theme attribute (in the form "<code>?[<i>package</i>: [<i>type</i>:]<i>name</i></code>") containing a value of this type.
@attr name com.example:typeface
*/
public static int MyTextView_typeface = 0;
答案 0 :(得分:4)
几年前,R.java中的引用并不是最终的。
这样做的原因是,如果您的主项目依赖于多个库项目,则生成的ID可能会发生冲突。
以下是对此的更多解释:http://tools.android.com/tips/non-constant-fields