自定义Actionbar样式

本文介绍如何在不同Android主题下自定义ActionBar样式,包括背景颜色、图标颜色等,并提供针对API14及以上版本的具体实现方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

备注: Theme.Holo.xxx主题下TabBar Tab项,仅能显示标题,无法显示指定的图片,可以改为“Theme.Black”或“Theme.Light"

以下内容为转载:

1)、在res/values/styles目录下,使用的是Theme.Sherlock.Light.DarkActionBar
          自定义的时候,只需要覆盖它的actionBarStyle即可:

<style name="AppBaseTheme" parent="Theme.Sherlock.Light.DarkActionBar"></style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    <item name="actionBarStyle">@style/MyActionBarStyle</item>
</style>
    
<style name="MyActionBarStyle" parent="@style/Widget.Sherlock.Light.ActionBar.Solid.Inverse">
    <item name="background">@drawable/ab_custom_blue_holo_light</item>
</style>

当然,对应的字体颜色,图标颜色,菜单样式等等,都可能会变得不那么协调了,这需要多覆盖几项其它样式,比如字体颜色,图标的普通样式和按下样式等。  

    2)、在res/values-14/styles.xml下,只需要覆盖系统定义的即可:

<!--
        Base application theme for API 14+. This theme completely replaces
        AppBaseTheme from BOTH res/values/styles.xml and
        res/values-v11/styles.xml on API 14+ devices.
    -->
    <style name="AppBaseTheme" parent="android:Theme.Holo.Light">

        <!-- API 14 theme customizations can go here. -->
        <item name="android:actionBarStyle">@style/MyActionBarStyle</item>
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme"></style>

    <style name="MyActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar">
        <item name="android:background">@drawable/ab_custom_blue_holo_light</item>
    </style>
 
 
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值