android-如何创建xml的ID? [英] android - How to create xml's id?
问题描述
我正在使用软键盘示例开发动态键盘应用程序.我的应用程序更改了布局.例如,我有一个键盘(有一个键),然后我设置了应用程序,然后可以使用键盘(有一个键).
I'm developing a dynamic keyboard application using soft keyboard sample. My application changes layout. For example I have a keyboard(has one key) then I set up the app and I can use keyboard(has one key).
我想在编译后创建一个XML文件,并在应用程序中使用该文件(使用xmlpullparser或xmlresourceparser读取XML文件).但是,键盘类需要XML的ID.如何创建XML ID?
I want to create an XML file after compilation and use this file in the application (reading XML file with xmlpullparser or xmlresourceparser). However, keyboard class needs XML's id. How do I create an XML id?
推荐答案
可以在ids.xml
或res\values
文件夹内的任何自定义文件(例如constants.xml
)中定义.
It can be defined in ids.xml
or any custom file like constants.xml
inside your res\values
folder.
示例:
<resources>
<item type="id" name="keyboard" />
</resources>
,并且可以通过以下代码进行访问:
and can be accessed in the code as following:
R.id.keyboard
这篇关于android-如何创建xml的ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!