【问题标题】:Android theming Actionbar tabAndroid 主题操作栏选项卡
【发布时间】:2014-09-11 11:21:23
【问题描述】:

我想像这样自定义我的标签

即选中的选项卡将具有白色背景,而未选中的选项卡将具有绿色背景。

到现在我都能做到

为了实现这一点,我将以下作为我的风格:-

<resources>
    <style name="ActionBar" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
        <item name="android:background">@color/sa_green</item>
        <item name="android:backgroundStacked">@color/stacked_green</item>
        <item name="android:backgroundSplit">@color/sa_green</item>
    </style>

    <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
        <item name="android:actionBarStyle">@style/ActionBar</item>
    </style>
</resources>

color.xml

<resources>
    <color name="sa_green">#14a804</color>
    <color name="stacked_green">#118504</color>
    <color name="accent_green">#97e08f</color>
</resources>

如何去除蓝色指示器并根据选择的选项卡更改背景?

【问题讨论】:

标签: android android-tabhost android-theme android-tabs android-style-tabhost


【解决方案1】:

您需要一个选择器 xml,而不仅仅是 @color/sa_green。选择器会根据标签的状态告诉标签使用什么颜色。

你可以这么简单:

drawable/tab_selector.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="false"
      android:background="@color/green" />
    <item android:state_pressed="true"
      android:drawable="@color/white" />
</selector>

那你只需要放

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

在您的主题中

并以您的风格声明 ActionBar,如下所示:

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

应该就是这样

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-13
    • 1970-01-01
    • 1970-01-01
    • 2013-02-14
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    相关资源
    最近更新 更多