Android的风格与主题
风格(style )与主题(theme)
1.Style和Theme都是用来定义界面的样式的。
2.Style是针对某个控件或者某组控件的样式,比如 TextView,EditText。
3. Theme必须针对整个Activity或者整个Application。
Style开发步骤:
1. 在res/values/styles.xml中创建样式标签:
<stylename="main_tv_style">
<itemname="android:textColor">#F00</item>
<itemname="android:textSize">18sp</item>
</style>
2. 在layout布局中使用样式:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world"
style="@style/main_tv_style" />
Style的继承开发步骤方式:
1.在res/values/styles.xml中创建样式标签:
<stylename="wrap_content_style" >
<itemname="android:layout_width">wrap_content</item>
<itemname="android:layout_height">wrap_content</item>
</style>
<!-- 定义一组样式 -->
<style name="main_tv_style" parent="@style/wrap_content_style">
<itemname="android:textColor">#F00</item>
<itemname="android:textSize">18sp</item>
</style>
2. 在layout布局中使用样式:
<TextView
android:text="@string/hello_world"
style="@style/main_tv_style"/>
Theme开发步骤:
1.在res/values/styles.xml中创建样式标签:
<stylename="AppTheme" parent="AppBaseTheme">
<itemname="android:background">#F00</item>
</style>
2.AndroidMenifest.xml设置
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:theme="@style/AppTheme" />