這篇文章主要講解了“Android中的string.xml文件怎么使用”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“Android中的string.xml文件怎么使用”吧!
創(chuàng)新互聯(lián)建站堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都網(wǎng)站制作、網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿(mǎn)足客戶(hù)于互聯(lián)網(wǎng)時(shí)代的萬(wàn)載網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
1.在程序中獲取string.xml中字符串和數(shù)值
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="hello">Hello World, MainActivity!</string> <string name="app_name">TestExample01</string> </resources>
在Activity中使用:
String appName=(String) this.getResources().getText(R.string.app_name); Log.i("test", "appName="+appName);
或者:
String appName=(String) this.getResources().getString(R.string.app_name); Log.i("test", "appName="+appName);
2.定義string數(shù)組(arrays.xml)
<?xml version="1.0" encoding="utf-8"?> <resources> <string-array name="sports"> <item>足球</item> <item>籃球</item> <item>太極</item> <item>冰球</item> </string-array> </resources> ----getResources().getStringArray(R.string.sports);
3.定義顏色(colors.xml)
<?xml version="1.0" encoding="utf-8"?> <resources> <color name="black">#FFFFFF</color> </resources> ---getResources().getDrawable(R.string.black); ---getResources().getColor(R.string.black);
4.定義尺寸(dimens.xml)
<?xml version="1.0" encoding="utf-8"?> <resources> <dimen name="height">80dip</dimen> </resources> ---getResource().getDimension(R.string.height);
5.定義樣式(styles.xml)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="sharpText">
<item name="android:textSize">18sp</item>
<item name="android:textColor">#000000</item>
</style>
</resources>
感謝各位的閱讀,以上就是“Android中的string.xml文件怎么使用”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)Android中的string.xml文件怎么使用這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!
當(dāng)前文章:Android中的string.xml文件怎么使用
網(wǎng)頁(yè)路徑:http://aaarwkj.com/article20/iippjo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供ChatGPT、手機(jī)網(wǎng)站建設(shè)、移動(dòng)網(wǎng)站建設(shè)、網(wǎng)站營(yíng)銷(xiāo)、品牌網(wǎng)站制作、面包屑導(dǎo)航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)