Reference in R.java not final

こ雲淡風輕ζ 提交于 2019-12-12 21:13:47

问题


When generating the reference for a stylable attribute there seems to be something going wrong in the generation of the R.java file.

One would expect the declaration of the field to be final but it is not. How come?

res/values/attrs.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="MyTextView">
        <attr name="typeface" format="string"/>
    </declare-styleable>
</resources>

gen/com.example/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;

回答1:


References inside R.java are not final since a couple of years ago.

The reason for this is that the ids generated might clash if you had several library projects that your main project depends on.

Here is more explanation on this: http://tools.android.com/tips/non-constant-fields



来源:https://stackoverflow.com/questions/26634871/reference-in-r-java-not-final

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!