1.样式和主题的使用:
样式用于为界面元素定义形式风格,是对界面布局文件xml的补充。使用样式可以指定多个控件具有的重复属性,避免了代码冗余。但样式只能作用于单个View,像EditText、TextView。主题也是包含了一个或多个View控件属性的集合。但主题是通过AndroidManifest.xml中的和节点作用于整个应用。样式的优先级高于主题。
样式:
<RelativeLayout style="@style/h_wrap_content"
。。。
<TextView
style="@style/tv_style"
。。。
<TextView
style="@style/tv_style"
。。。
</RelativeLayout>
主题:
<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/AppTheme">
<activity android:name=".MainActivity">
......
2.样式文件定义
在res/values文件夹下,new—>values resource file,文件名自定义:
<resources>
<style name="TextStyle">
<item name="android:layout_width">wrap_content</item>
<item name="">hhh</item>
...
</style>
<style name="MyTheme">
<item> </item>
</style>
</resoures>
自定义样式还可以通过parent=”XXStyle”继承其他样式和主题。
3.国际化:新建values文件夹的命名规则(values-语言代码-r国家或地区)。
效果对比:退出程序,打开系统设置(setting菜单),依次选择language&input—>language—>”简体中文”,完成后重新进入程序即可。