“无法解析符号"使用android:id =“" @ + android:id/my_id“时出错 [英] "Cannot Resolve Symbol" Error when using android:id="@+android:id/my_id"
问题描述
当我向名称空间添加android:id/background时,Lint抱怨它无法解析符号",即使我请求添加它而不是调用它.该代码按编写的方式工作,但错误仍然存在.当我更改<item android:id="@+android:id/background" to <item android:id="@+id/background"
时,应用程序停止工作(另一个调用中断).我的问题是:为什么Lint不能识别我将android:id/background添加到名称空间,即使对其的调用功能正常?有什么更好的方法可以为该商品提供不会掉毛的ID?
When I am adding android:id/background to the namespace, Lint complains that it "Cannot Resolve Symbol" even though I am requesting to add it rather than call it. The code works as written, but the error persists. When I change <item android:id="@+android:id/background" to <item android:id="@+id/background"
, the application stops working (another call breaks). My question is: why does Lint not recognize me adding android:id/background to the namespace even though a call to it functions well? Is there some better way to give this item an id that won't have Lint throw an error?
下面的层列表中所有三个名称空间项的定义都引发了lint错误:
All three of the namespace definitions for the items in the layer-list below throw a lint error:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+android:id/background"
android:drawable="@drawable/custom_ratingbar_empty" />
<item android:id="@+android:id/secondaryProgress"
android:drawable="@drawable/custom_ratingbar_empty" />
<item android:id="@+android:id/progress"
android:drawable="@drawable/custom_ratingbar_filled" />
</layer-list>
我发现了此,并尝试运行build-> clean没有成功.
I found this and tried running build->clean as suggested with no success.
推荐答案
如果要创建自己的ID:
If you are creating your own id:
"@+id/your_new_id"
如果您正在访问已创建的ID
if you are accessing your already created id
"@id/your_old_id"
如果您尝试访问Android系统创建的ID
if you are trying to access Android's system created id
"@android:id/system_id"
您可以看到区别,如果您要创建自己的ID,则必须添加+
.由于您正在访问系统ID,因此不必添加+
you can see the difference, if you are creating your own id then you have to add +
. Since you are accessing system ID so you don't have to add +
这篇关于“无法解析符号"使用android:id =“" @ + android:id/my_id“时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!