日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【android-tips】关于string.xml的使用

發(fā)布時間:2025/4/5 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【android-tips】关于string.xml的使用 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

?(轉(zhuǎn)載請注明出處:http://blog.csdn.net/buptgshengod?

1.介紹

在制作android應(yīng)用的時候,常常用到很多string,就是一些文字,這里介紹一種方法,將所有string封裝在一個string.xml文件中,通過styles.xml控制string的大小等屬性。在代碼中,只要調(diào)用string的id即可。這樣符合面向?qū)ο蟮木幊趟枷?#xff0c;而且也能使android應(yīng)用更好的適應(yīng)各種分辨率的手機!

2.具體實現(xiàn)

? ? ?首先,我們在value文件夾下建立string.xml用于存放string,建立styles.xml用于控制string的屬性。(無視其他xml)
在string.xml中,我們聲明一些string,注意name <?xml version="1.0" encoding="utf-8"?> <resources><string name="hello">Hello World, GameActivity!</string><string name="app_name">鏢鏢必達</string><string name="help">幫助信息\n此游戲是一款單指飛鏢游戲\n點擊屏幕發(fā)射飛鏢\n連擊可以獲得更高分數(shù)</string><string name="about">關(guān)于游戲\n\n薊門邊IT創(chuàng)意工作室出品\nRhythmMaker原班人馬打造\n單指RPG手游巔峰之作\n技術(shù):zixiyaoren@gmail.com\n美術(shù):Rou7in@gmail.com</string><string name="title_activity_other">OtherActivity</string><string name="action_settings">Settings</string><string name="hello_world">Hello world!</string></resources>
在styles.xml中 <resources><!--Base application theme, dependent on API level. This theme is replacedby AppBaseTheme from res/values-vXX/styles.xml on newer devices.--><style name="AppBaseTheme" parent="android:Theme.Light"><!--Theme customizations available in newer API levels can go inres/values-vXX/styles.xml, while customizations related tobackward-compatibility can go here.--></style><!-- Application theme. --><style name="AppTheme" parent="AppBaseTheme"><!-- All customizations that are NOT specific to a particular API-level can go here. --></style> <style name="label_white"><item name="android:textSize">38px</item>//字體大小<item name="android:textColor">#0000FF</item>//顏色是藍色<item name="android:gravity">center</item>//居中<item name="android:textStyle">bold</item>//加粗</style></resources> 配置完xml文件,我們看看在代碼中怎么調(diào)用!
? ?比如我們要調(diào)用string.xml中命名為help的string。只要在對象中類似于這種setText(R.string.help);調(diào)用方法就可以,跟圖片的用法是一樣的!



《新程序員》:云原生和全面數(shù)字化實踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀

總結(jié)

以上是生活随笔為你收集整理的【android-tips】关于string.xml的使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。