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

一.修改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>

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

效果

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值