codecamp

Android 字符串数组资源

你可以在/res/values子目录下的任何文件中将字符串数组指定为资源。

例子

你可以使用名为string-array的XML节点。此节点是资源的子节点。

以下代码显示资源文件中的数组示例。

<?xml version="1.0" encoding="utf-8"?>
<resources>
      <string name="hello">hello</string>
      <string name="app_name">hello appname</string>
      <string-array name="test_array">
                 <item>one</item>
                 <item>two</item>
                 <item>three</item>
      </string-array>
</resources>

一旦你有这个字符串数组资源定义,你可以在Java代码中检索这个数组,如下。

// www.w3cschool.cn
//Get access to Resources object from an Activity
Resources res = your_Activity.getResources();
String strings[] = res.getStringArray(R.array.test_array);

//Print strings
for (String s: strings)
{
    Log.d("example", s);
}


Android 字符串资源格式
Android 颜色资源
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }