@android的含义

3
我想问一下在android:id="@android:id/list"中,@android的含义是什么。我在不同的Android示例和教程中看到过它,并且也在Google上搜索过。我找到的唯一解释是来自http://developer.android.com/resources/tutorials/notepad/notepad-ex1.html的“列表和空ID由Android平台为我们提供,因此,我们必须使用android:前缀来声明id”。谢谢。

我没有做任何研究,但我猜测这是一种命名空间机制,以便内置的 ID 不会与应用程序特定的 ID 冲突。命名空间下的 ID 可能具有某些特殊含义,但我不知道。 - John Chadwick
请查看此线程 https://dev59.com/yW445IYBdhLWcg3wH2vH#5025971。 - Lalit Poptani
1个回答

4

Android:

包含应用程序使用的资源类,并为系统功能定义应用程序权限。

您可以直接从这些R类中使用一些资源在自己的应用程序中,但通常情况下,您应该只使用您直接提供的资源来提供一个具有无外部依赖性的连贯应用程序包。特别是,您不应该使用来自android包的可绘制资源,因为它们可能会在平台版本之间发生更改,从而导致与您的设计产生意想不到的冲突。通常,样式是您应该直接使用这些资源中的唯一资源。

所以你可以通过在xml文件中使用'@android:id'来使用android的资源,如列表、空等。

@+id和@android:id的区别:

@+id/foo means you are creating an id named foo in the namespace of
your application. You can refer to it using @id/foo. @android:id/foo
means you are referring to an id defined in the android namespace.
This namespace is the namespace of the framework. In this case, you
need to use @android:id/list and @android:id/empty because these are
the id the framework expects to find (the framework knows only about
the ids in the android namespace.

谢谢。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接