- Resources Resources = getBaseContext().getResources();
Resources Resources = getBaseContext().getResources();
一、strings.xml代码
- xml version="1.0" encoding="utf-8"?>
- <resources>
- <string name="hello">Hello World, Main!string>
- resources>
Hello World, Main!
获取代码:
- String app_name = getResources().getString(R.string.app_name);
String app_name = getResources().getString(R.string.app_name);
二、arrays.xml代码
- xml version="1.0" encoding="utf-8"?>
- <resources>
- <array
- name="items">
- <item>中国item>
- <item>日本item>
- <item>韩国item>
- array>
- <integer-array
- name="moneys">
- <item>100item>
- <item>200item>
- <item>300item>
- <item>400item>
- <item>500item>
- integer-array>
- <string-array
- name="levels">
- <item>一等级item>
- <item>二等级item>
- <item>三等级item>
- string-array>
- resources>
- 中国
- 日本
- 韩国
- 100
- 200
- 300
- 400
- 500
- 一等级
- 二等级
- 三等级
获取代码:
- String items[] = getResources().getStringArray(R.array.level);
- int int_array[] = getResources().getIntArray(R.array.moneys);
String items[] = getResources().getStringArray(R.array.level);
int int_array[] = getResources().getIntArray(R.array.moneys);
三、colors.xml代码
- xml version="1.0" encoding="utf-8"?>
- <resources>
- <color name="white">#ffffffcolor>
- <color name="black">#000000color>
- <color name="grey">#333333color>
- <color name="yellow">#fccf29color>
- resources>
#ffffff
#000000
#333333
#fccf29
获取代码:
- int color = getResources().getColor(R.color.yellow);
- textView1.setTextColor(color);
-
int color = getResources().getColor(R.color.yellow);
textView1.setTextColor(color);
//或者写成textView1.setTextColor(Color.YELLOW);
四、styles.xml代码
- xml version="1.0" encoding="utf-8"?>
- <resources>
- <style name="titleText">
- <item name="android:textSize">18pxitem>
- <item name="android:textColor">#213255item>
- <item name="android:background">#888888item>
- style>
- resources>
获取代码(xml):
style="@style/titleText"
五、dimens.xml代码
- xml version="1.0" encoding="utf-8"?>
- <resources>
- <dimen name="big_font">30pxdimen>
- <dimen name="middle_font">20pxdimen>
- <dimen name="small_font">10pxdimen>
- resources>
30px
20px
10px
获取代码:
- float dimens = getResources().getDimension(R.dimen.big_font);
- xml_dimens.setTextSize(dimens);
阅读(547) | 评论(0) | 转发(0) |