@id/和@+id/有什么区别?

在@+id/中,加号+指示创建一个新的资源名并添加到R.java文件中,但是@id/呢?从ID的文档:当引用一个Android资源ID时,你不需要加号,但必须添加Android包的命名空间,如下所示:

android:id="@android:id/list"

但是在下图中,Eclipse并没有建议使用任何@android:id/。

@id/和@android:id/相同吗?


当前回答

Android中“@+id/”和“@id/”的区别

第一个用于创建特定ui组件的ID,另一个用于引用特定组件

其他回答

摘自开发者指南:

android:id="@+id/my_button"

The at-symbol (@) at the beginning of the string indicates that the XML parser should parse and expand the rest of the ID string and identify it as an ID resource. The plus-symbol (+) means that this is a new resource name that must be created and added to our resources (in the R.java file). There are a number of other ID resources that are offered by the Android framework. When referencing an Android resource ID, you do not need the plus-symbol, but must add the android package namespace, like so:

android:id=“@android:id/empty”

很简单:

“@ +……”-创建新的

“@……”-现有链接

来源:https://developer.android.com/guide/topics/resources/layout-resource.html idvalue

Eclipse中有一个bug,有时如果你创建了一个新的@+id/..,它不会立即添加到R.java文件中,即使在清理构建项目之后也是如此。解决方案是重新启动Eclipse。

我认为这个问题应该尽快解决,因为它可能(从经验来看,将会)使一些开发人员感到困惑,认为他们的语法有问题,并试图调试它,即使实际上没有什么需要调试的。

Android中“@+id/”和“@id/”的区别

第一个用于创建特定ui组件的ID,另一个用于引用特定组件

+号是将id添加到资源id列表的快捷方式。否则,您需要将它们保存在这样的xml文件中

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <item name="my_logo" type="id"/>
</resources>