【问题标题】:how to change the highlighted color of tab bar in android如何在android中更改标签栏的突出显示颜色
【发布时间】:2014-12-27 15:00:47
【问题描述】:

我想更改标签栏的突出显示颜色。我还将使用 Android 操作栏样式生成器来更改颜色,但它不会改变。

Style.xml

<resources>

<style name="Theme.Example" parent="@android:style/Theme.Holo">

  <item name="android:actionBarTabStyle">@style/ActionBarTabStyle.Example</item>

</style>

 <style name="ActionBarTabStyle.Example" parent="@android:style/Widget.Holo.ActionBar.TabView">
     <item name="android:background">@drawable/tab_indicator_ab_example</item>
  </style>

</resources>

tab_indicator_ab_example

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Non focused states -->
    <item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@android:color/transparent" />
    <item android:state_focused="false" android:state_selected="true"  android:state_pressed="false" android:drawable="@drawable/tab_selected_example" />

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

    <!-- Pressed -->
    <!--    Non focused states -->
    <item android:state_focused="false" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_unselected_pressed_example" />
    <item android:state_focused="false" android:state_selected="true"  android:state_pressed="true" android:drawable="@drawable/tab_selected_pressed_example" />

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

请指导我更改标签栏的突出显示颜色

【问题讨论】:

    标签: android android-layout android-tabhost android-theme


    【解决方案1】:

    我已将此代码添加到我的应用程序中。现在您可以轻松地将此代码放入您的应用程序中,我希望这对您很有效。

    请把下面这个文件放到你的drawable文件夹中,并将这个文件设置为你的背景。

    tab_bg_selector.xml

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    
        <item android:drawable="@color/tab_selected" android:state_pressed="true"/>
        <item android:drawable="@color/tab_selected" android:state_selected="true"/>
        <item android:drawable="@color/tab_normal"/>
    
    </selector>
    

    将此代码放入您的 res -> values -> color.xml

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
    <color name = "tab_normal"> #FF0000 </color>
    <color name = "tab_selected"> #000000 </color>
    </resources>
    

    【讨论】:

    • 给出错误没有找到与给定名称匹配的资源(在“可绘制”处,值为“@color/tab normal”)。 tab_bg_selector.xml
    • 请将此文件插入您的 res --> values --> color.xml,而不是您的可绘制文件夹。我已经编辑了上面的 color.xml 文件,请把这个文件放到上面的路径中。我 100% 确定这对您来说会很好。
    • 在 value 文件夹中插入 color.xml 后颜色没有改变
    • 给我你的邮件ID,我会给你发送代码你也可以检查这个代码
    【解决方案2】:

    尝试使用http://jgilfelt.github.io/android-actionbarstylegenerator/ 这是最简单的方法..

    1) 使用 UI 为不同的项目选择颜色
    2) 完成后点击“下载 .ZIP”
    3) ZIP 文件包含您必须复制到项目 res/layout 和 res/drawableXXXX 文件夹中的资源文件

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-14
      • 2012-03-27
      • 1970-01-01
      • 2011-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-17
      相关资源
      最近更新 更多