【问题标题】:ActionBar Tab indicator colorActionBar 选项卡指示器颜色
【发布时间】:2015-05-12 10:11:35
【问题描述】:

我想知道如何更改标签指示器的颜色。我尝试了多个代码,但都没有工作,所以请帮我如何更改默认颜色?我正在使用以下代码:

actionBar.setStackedBackgroundDrawable(getResources()
                        .getDrawable(R.drawable.tab_selector));

tab_selector.xml

--> --> -->

<!-- Focused states -->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/cab_background_top_example" />
<item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/cab_background_top_example" />

<!-- Pressed -->
<item android:state_selected="true" android:state_pressed="true" android:drawable="@color/tabcolor" />
<item android:state_pressed="true" android:drawable="@color/tabcolor" />

【问题讨论】:

标签: android android-actionbar


【解决方案1】:

制作自定义操作栏。使用这个http://jgilfelt.github.io/android-actionbarstylegenerator/

【讨论】:

【解决方案2】:

使用样式也可以做到这一点(代码基于 support-v7 库)

    <style name="MyAppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">

             <item name="android:actionBarTabStyle">@style/MyActionBarTabs</item> 
             <item name="actionBarTabStyle">@style/MyActionBarTabs</item>

    </style>

    <style name="MyActionBarTabs" parent="@style/Widget.AppCompat.ActionBar.TabView">

       <item name="android:background">@drawable/tab_selector</item>
        <item name="background">@drawable/tab_selector</item> 

    </style>

欲了解更多信息,请访问Official Doc: Styling the Action Bar

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-12
    • 1970-01-01
    • 2015-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多