Android--(14)--通过安卓选择器来修改actionbar的样式与字体样式

来源:互联网 发布:金蝶引出数据失败原因 编辑:程序博客网 时间:2024/05/17 03:03

一.修改actionbar样式的基本步骤:
1.首先在drawable文件夹下新建一个选择文件select_style.xml备用,代码如下:

selector的常用属性:
android:state_selected : 表示是否为选中状态
android:state_pressed : 表示是否为点击状态
然后根据不同的状态来设定不懂得效果

<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android" >    <!-- 未选中未点击 -->    <item  android:state_selected="false"            android:state_pressed="false"            android:drawable="@drawable/top_3" />      <!-- 选中未点击 -->    <item android:state_selected="true"            android:state_pressed="false"            android:drawable="@drawable/top_2" />  </selector>

2.重写actionBarTabStyle属性,然后将它指向一个新建的Tab样式;并在此样式中将background属性指定为刚创建的选择样式;代码如下:

<resources xmlns:android="http://schemas.android.com/apk/res/android">    <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">        <item name="android:actionBarTabStyle">@style/actionBarStyle</item>    </style>    <!-- 创建的style样式 -->    <style name="actionBarStyle" parent="@android:style/Widget.Holo.ActionBar.TabView">        <item name="android:background">@drawable/select_style</item>    </style></resources>

到此样式设置就完成啦;

二.设置字体颜色
重写android:actionBarTabTextStyle属性
将style修改为如下方式:

<resources xmlns:android="http://schemas.android.com/apk/res/android">    <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">                <item name="android:actionBarTabTextStyle">@style/actionTextstyle</item>        <item name="android:actionBarTabStyle">@style/actionBarStyle</item>    </style>        <!-- 设置标题Tab的字体样式 -->    <style name="actionTextstyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">        <item name="android:textColor">@drawable/select_text</item>        <item name="android:textSize">18sp</item>    </style>    <!-- 创建的style样式 -->    <style name="actionBarStyle" parent="@android:style/Widget.Holo.ActionBar.TabView">        <item name="android:background">@drawable/select_style</item>    </style></resources>

没啥技术含量,重写某一属性就行

效果