样式
样式:把控件中用到的相同的属性抽取成样式,在res目录下的values目录的styles.xml文件中声明style节点,在style节点下可以声明item节点,每个item节点对应着一个属性。如果values目录下没有styles.xml文件,就创建它。
声明textViewStyle样式
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="textViewStyle">
<item name="android:background">#22000000</item>
<item name="android:layout_width">100dp</item>
<item name="android:layout_height">100dp</item>
<item name="android:textColor">#ff000000</item>
<item name="android:textSize">26sp</item>
</style>
</resources>
引用textViewStyle样式
<TextView
android:id="@+id/textView"
android:text="static load fragment!"
style="@style/textViewStyle"/>
主题
主题的作用和样式类似,只不过作用的范围不同,主题作用在整个应用,需要在androidManifest.xml中的Application节点的android:theme属性设置,这里设置的当前应用的主题。
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Fragment">
</application>
国际化
如果要支持中文环境,需要在res目录下创建一个values-zh目录,在这个目录中放一个string.xml文件,这个文件中的所有内容均是用中文写的;如果要支持英文,也是同样的做法,只不过新建的目录应为values-en。