styles(样式)抽取出控件的共同的属性
例如以下代码:
<style name="my_text_style">
<item name="android:textSize">20dip</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#ff0000</item>
</style>
如何继承style呢?
第一种方式:
<style name="my_text_style2" parent="@style/my_text_style">
<item name="android:textColor">#0000ff</item>
</style>
第二种方式:
<style name="my_text_style.my_text_style3">
<item name="android:textColor">#00ff00</item>
</style>
第三种方式:
在styles xml文件中生成,其实theme是一个特殊的style
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="my_theme">
<item name="android:background">#ff0000</item>
</style>
2,主题的应用
在清单文件中的application中
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/my_theme" >
根据自己写的样式中application中的theme选择
例如以下代码:
<style name="my_text_style">
<item name="android:textSize">20dip</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#ff0000</item>
</style>
如何继承style呢?
第一种方式:
<style name="my_text_style2" parent="@style/my_text_style">
<item name="android:textColor">#0000ff</item>
</style>
第二种方式:
<style name="my_text_style.my_text_style3">
<item name="android:textColor">#00ff00</item>
</style>
第三种方式:
在使用的时候,把想改变的属性给覆盖掉就行了。
theme的应用
1,创建主题在styles xml文件中生成,其实theme是一个特殊的style
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="my_theme">
<item name="android:background">#ff0000</item>
</style>
2,主题的应用
在清单文件中的application中
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/my_theme" >
根据自己写的样式中application中的theme选择