国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

Android Values文件作用及使用方法

2019-11-06 09:40:07
字體:
供稿:網(wǎng)友

Android valuses

位于app/res/values文件是用來存放安卓資源的資源的文件其中包括四個個xml文件:

這里寫圖片描述

1. colors.xml 保存顏色資源

例如:

<resources> <!-- Base application theme. --> <style name="A

2. dimens.xml 尺寸控制

<resources> <!-- Default screen margins, per the Android Design guidelines. --> <dimen name="activity_horizontal_margin">16dp</dimen> <dimen name="activity_vertical_margin">16dp</dimen></resources>

dimens.xml(w820dp) 先解釋一下w820dp的意思,(可能是為電視設(shè)置的) 1. values-w820dp表明這個目錄下的資源所要求屏幕的最小寬度是820dp。 2. Samsung G920V的屏幕配置參數(shù):1440x2560像素,屏幕尺寸5.1寸,dpi=576.所以,Samsung G920V的最小屏幕寬度為:400dp (1440 * 160 / 576),因此不滿足w820dp的要求。

<resources> <!-- Example customization of dimensions originally defined in res/values/dimens.xml (such as screen margins) for screens with more than 820dp of available width. This would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). 示例自定義維度最初定義在res /價值/ dimens.xml (如屏幕邊緣)的屏幕寬度超過820 dp的可用。這 包括7“10”設(shè)備景觀(~ 960 dp ~ 960 dp分別)。--> <dimen name="activity_horizontal_margin">64dp</dimen></resources>

3. string.xml

<resources> <string name="app_name">MyFirst</string></resources>

4. style.xml

<resources> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> </style></resources>

引用方式舉例: 在代碼中通過 R.string.app_name 可以獲取app_name所對應(yīng)的字符串(MyFirst) 在XML中通過 @string/app_name 可以獲取app_name所對應(yīng)的字符串(MyFirst) (其他同理,相信聰明的你可以使用)


知其然,思其所以然 為什么要這么復(fù)雜? 這么復(fù)雜有卵用?

首先,這樣做不復(fù)雜,反而更加方便。倘若一個程序中好多地方用到了一個String,要是沒用這種全局常量的方式,需要一個一個地方改,反之則只需改一次,是不是方便了很多,雖然有的IDE有這個一改全改的功能,但是這是一種組件的開發(fā)思想。使用這種全局常量的方式也便于日后擴展復(fù)用等。


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 甘肃省| 新疆| 隆昌县| 滦平县| 时尚| 白水县| 淮北市| 泉州市| 宣汉县| 阿鲁科尔沁旗| 棋牌| 广东省| 密云县| 邵武市| 天等县| 澄江县| 平原县| 耒阳市| 荔波县| 垦利县| 依安县| 泽普县| 阿拉尔市| 水城县| 信阳市| 景德镇市| 阿巴嘎旗| 临湘市| 六枝特区| 台南市| 德江县| 都江堰市| 恭城| 开封县| 蒙自县| 浠水县| 香格里拉县| 凤翔县| 同德县| 齐河县| 稷山县|