你可以在/res/values子目錄下的任何文件中將字符串數(shù)組指定為資源。
你可以使用名為string-array的XML節(jié)點。此節(jié)點是資源的子節(jié)點。
以下代碼顯示資源文件中的數(shù)組示例。
<?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>
一旦你有這個字符串數(shù)組資源定義,你可以在Java代碼中檢索這個數(shù)組,如下。
// m.o2fo.com //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); }
更多建議: