R.java中的引用不是最终的 [英] Reference in R.java not final

查看:54
本文介绍了R.java中的引用不是最终的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在生成可样式化属性的引用时,似乎在R.java文件的生成中出现了问题.

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

人们希望字段的声明为 final ,但事实并非如此.怎么会来?

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

res/values/attrs.xml

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

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;

推荐答案

R.java中的引用自几年前不是最终的.

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

这样做的原因是,如果您有几个主要项目依赖的库项目,则生成的ID可能会冲突.

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

这里有更多解释: http://tools.android.com/tips/non-constant-fields

这篇关于R.java中的引用不是最终的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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