在引用Android XML资源时,星号(*)的含义是什么?

时间:2013-03-27 01:17:45

标签: android

此Android代码的含义是什么?

*+和空白之间有什么区别:

@*android:id

在android_ics / packages / apps / Setting / res / layout

中是这样的
<TextView android:id="@*android:id/timeDisplayForeground"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:singleLine="true"
    android:ellipsize="none"
    android:textSize="@dimen/crypt_clock_size"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="@color/crypt_keeper_clock_foreground"
    android:layout_alignLeft="@*android:id/timeDisplayBackground"
    android:layout_alignTop="@*android:id/timeDisplayBackground"
    android:layout_marginBottom="6dip" />

2 个答案:

答案 0 :(得分:5)

*允许您访问私人资源。私有资源是私有的,因为他们的名字将来可能会作为固件或皮肤更新的一部分而改变。

使用这些资源并不是一个好主意,除非您在一个环境中工作,在这种情况下,您知道这些资源将来不会发生变化并破坏您的应用。

在您的示例中,系统应用程序正在引用私有资源,您最常见的就是使用此引用。

答案 1 :(得分:1)

我之前回答过,但可能误解了你的问题。项目中有一个名为R.java的生成文件,其中列出了您的资源。例如,当您创建视图并添加按钮时,您会看到一些信息会自动进入您的R.java文件。在Java中,您可以使用这些成员访问信息。但是,在XML中,您必须通过引用标签或节点来访问它们。

@android:id refers to the public system member called "id"
@id refers to one that you've created
@+id says to create one called "id" (and what to set it to)
@*android:id refers to a private system member

请参阅:http://developer.android.com/training/basics/firstapp/building-ui.html