public static final class R.id
extends Object
java.lang.Object | |
↳ | android.R.id |
Constants | |
---|---|
int | accessibilityActionContextClick Accessibility action identifier for |
int | accessibilityActionScrollDown Accessibility action identifier for |
int | accessibilityActionScrollLeft Accessibility action identifier for |
int | accessibilityActionScrollRight Accessibility action identifier for |
int | accessibilityActionScrollToPosition Accessibility action identifier for |
int | accessibilityActionScrollUp Accessibility action identifier for |
int | accessibilityActionSetProgress Accessibility action identifier for |
int | accessibilityActionShowOnScreen Accessibility action identifier for |
int | addToDictionary Menu ID to perform a "add to dictionary" operation. |
int | background |
int | button1 |
int | button2 |
int | button3 |
int | candidatesArea The part of the UI shown by an |
int | checkbox |
int | closeButton View ID of a |
int | content |
int | copy Context menu ID for the "Copy" menu item to copy the currently selected (or all) text in a text view to the clipboard. |
int | copyUrl Context menu ID for the "Copy URL" menu item to copy the currently selected URL from the text view to the clipboard. |
int | custom |
int | cut Context menu ID for the "Cut" menu item to copy and delete the currently selected (or all) text in a text view to the clipboard. |
int | edit |
int | empty |
int | extractArea The part of the UI shown by an |
int | hint |
int | home |
int | icon |
int | icon1 |
int | icon2 |
int | icon_frame |
int | input |
int | inputArea The part of the UI shown by an |
int | inputExtractEditText View ID of the text editor inside of an extracted text layout. |
int | keyboardView View ID of the |
int | list |
int | list_container |
int | mask |
int | message |
int | navigationBarBackground |
int | paste Context menu ID for the "Paste" menu item to copy the current contents of the clipboard into the text view. |
int | pasteAsPlainText |
int | primary |
int | progress |
int | redo |
int | replaceText |
int | secondaryProgress |
int | selectAll Context menu ID for the "Select All" menu item to select all text in a text view. |
int | selectTextMode Context menu ID for the "Select text..." menu item to switch to text selection context mode in text views. |
int | selectedIcon |
int | shareText |
int | startSelectingText Menu ID to perform a "start selecting text" operation. |
int | statusBarBackground |
int | stopSelectingText Menu ID to perform a "stop selecting text" operation. |
int | summary |
int | switchInputMethod Context menu ID for the "Input Method" menu item to being up the input method picker dialog, allowing the user to switch to another input method. |
int | switch_widget |
int | tabcontent |
int | tabhost |
int | tabs |
int | text1 |
int | text2 |
int | title |
int | toggle |
int | undo |
int |
ID型资源
在XML中定义的唯一资源ID。使用<item>元素中的提供的名称,Android开发工具会在工程的R.java类中创建一个唯一的整数,可以使用这个整数来标识一个应用程序资源(如,UI布局中的View对象),或者应用程序代码中使用的一个唯一整数(如,一个对话框或结果编码的ID)。
注意:ID资源是一种简单的资源,使用其name属性提供的值来引用资源。如,能够把ID资源与其他简单资源组合到一个XML文件的<resources>元素下。还有,要记住的是:ID资源不引用实际的资源项目,它只是一个能够跟其他资源绑定唯一ID,或是程序中使用的唯一整数。
文件位置(FILE LOCATION):
res/values/filename.xml
文件名是任意的。
资源引用(RESOURCE REFERENCE):
在Java代码中:R.id.name
在XML中:@[package:]id/name
语法(SYNTAX):
元素(ELEMENTS):
<resources>
必须的,它必须是根节点,没有属性。
<item>
定义一个唯一ID,不需要值。
属性(ATTRIBUTES):
type:必须设置为”id”
name:字符串值,给ID定义一个唯一的名称。
例子(EXAMPLE):
以下XML被保存在res/values/ids.xml文件中:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item type="id" name="button_ok" />
<item type="id" name="dialog_exit" />
</resources>
以下是把button_ok的ID资源设定给布局中的一个Button控件的方法:
<Button android:id="@id/button_ok"
style="@style/button_style" />
要注意的是:android:id属性的值在引用ID资源时没有包含“+”号,因为这个ID已经存在了,它在ids.xml文件中已经被定义了。(当使用“+”号指定资源ID时,如:android:id=”@+id/name”,则意味着这个ID不存在,应该给这个资源创建一个新的ID。)
在下面的示例中,代码使用中使用了“dialog_exit”ID来唯一标识一个对话框:
showDialog
(R.id.dialog_exit);
以下代码通过比较“dialog_exit”ID来创建对话框:
protectedDialogonCreateDialog(int)(int id){
Dialog dialog;
switch(id){
case R.id.dialog_exit:
...
break;
default:
dialog =null;
}
return dialog;
}