W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
你可以在/res/values子目錄下的任何文件中將字符串?dāng)?shù)組指定為資源。
你可以使用名為string-array的XML節(jié)點(diǎn)。此節(jié)點(diǎn)是資源的子節(jié)點(diǎn)。
以下代碼顯示資源文件中的數(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>
一旦你有這個(gè)字符串?dāng)?shù)組資源定義,你可以在Java代碼中檢索這個(gè)數(shù)組,如下。
// www.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); }
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: