android 获取values String

来源:互联网 发布:中科大软件学院调剂 编辑:程序博客网 时间:2024/06/03 15:22

http://developer.android.com/guide/topics/resources/string-resource.html

文件名:

res/values/filename.xml

文件内容:

<?xml version="1.0" encoding="utf-8"?><resources>    <string name="hello">Hello!</string></resources>

代码使用:

String string = getString(R.string.hello);

如果是

String Array 

 R.array.string_array_name

<?xml version="1.0" encoding="utf-8"?><resources>    <string-array name="planets_array">        <item>Mercury</item>        <item>Venus</item>        <item>Earth</item>        <item>Mars</item>    </string-array></resources>

使用:

Resources res = getResources();String[] planets = res.getStringArray(R.array.planets_array);

原文地址:http://blog.csdn.net/aikongmeng/article/details/41890163


0 0
原创粉丝点击