修改ActionBar样式小结

总的原理是自定义系统主题,继承系统主题,加上自定义item,覆盖父类的item样式.

<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
<!-- Customize your theme here. -->
<item name="android:colorPrimary">@color/colorPrimary</item>
<item name="android:colorPrimaryDark">@color/colorPrimaryDark</item>

<item name="android:actionBarTabTextStyle">@style/CustomTabTextStyle</item>
<item name="android:actionBarDivider">@drawable/bar_shape_divider</item>
<!--<item name="android:actionBarStyle">@style/MyActionBarStyle</item>-->
<item name="android:actionBarTabStyle">@style/CutomTabStyle</item>
>

自定义style:
<style name="CustomTabTextStyle" parent="@android:style/TextAppearance.Holo">
<item name="android:textColor">@color/tabTextColor</item>
</style>

<style name="MyActionBarStyle" parent="@android:style/Widget.Holo.ActionBar">
<item name="android:background">#05C0B9</item>
</style>

<style name="CutomTabStyle" parent="@android:style/Widget.Holo.ActionBar.TabView">
<item name="android:background">@drawable/bar_background_selector</item>
</style>


bar_background_selector:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/bar_shape2" android:state_selected="true"/>
<item android:drawable="@drawable/bar_shape1" android:state_selected="false"/>
</selector>

bar_shape1:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#05C0B9"/>
</shape>

bar_shape2:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape>
<solid android:color="#10B7BB"/>
</shape>
</item>
<item android:bottom="5dp">
<shape>
<solid android:color="@color/gray"/>
</shape>
</item>
</layer-list>


bar_shape_divider:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<solid android:color="@android:color/holo_blue_bright"/>
<stroke android:width="1dp" android:color="@color/gray"/>
<size android:width="3dp"
android:height="6dp"/>
</shape>

写的有点乱,核心思想在第一句.另外由于版本问题,对版本有要求,低版本可能无法修改样式,我用的是API21做的测试,理论上19以上都OK.

你可能感兴趣的:(修改ActionBar样式小结)