【问题标题】:how to change tab indicator underline height in actionbar如何更改操作栏中的选项卡指示器下划线高度
【发布时间】:2015-08-09 18:39:14
【问题描述】:

在我的操作栏中,我想最小化所选标签下划线的高度。我试图在drawable中最小化tab_selected.9.png、tab_selected_focused.9.png和tab_selected_pressed.9.png的高度。但没有任何影响,我想我走错了路。对于操作栏和选项卡,我使用 android.support.v7.app.ActionBar 和 android.support.v7.app.ActionBar.Tab。任何建议都非常感谢。

谢谢

主题.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
       parent="@style/Theme.AppCompat.Light.DarkActionBar">

    <!-- Support library compatibility -->
    <item name="actionBarTabStyle">@style/MyActionBarTabs</item>

</style>

<!-- ActionBar tabs styles -->
<style name="MyActionBarTabs"
       parent="@style/Widget.AppCompat.ActionBar.TabView">
    <!-- tab indicator -->
    <item name="android:background">@drawable/actionbar_tab_indicator</item>

    <!-- Support library compatibility -->
    <item name="background">@drawable/actionbar_tab_indicator</item>
</style>
</resources>

actionbar_tab_indicator.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<!-- STATES WHEN BUTTON IS NOT PRESSED -->

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

<!-- Focused states (such as when focused with a d-pad or mouse hover) -->
<item android:state_focused="true" android:state_selected="false"
      android:state_pressed="false"
      android:drawable="@drawable/tab_unselected_focused" 
      />
<item android:state_focused="true" android:state_selected="true"
      android:state_pressed="false"
      android:drawable="@drawable/tab_selected_focused" />


<!-- STATES WHEN BUTTON IS PRESSED -->

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

<!-- Focused states (such as when focused with a d-pad or mouse hover) -->
<item android:state_focused="true" android:state_selected="false"
      android:state_pressed="true"
      android:drawable="@drawable/tab_unselected_pressed" />
<item android:state_focused="true" android:state_selected="true"
      android:state_pressed="true"
      android:drawable="@drawable/tab_selected_pressed" />
</selector>

【问题讨论】:

  • 您正在使用不推荐使用的导航模式。检查设计支持库中的 TabLayout。

标签: android-actionbar android-actionbar-compat


【解决方案1】:

我在这个链接中找到了答案 - Is it possible to change actionbar tab indicator programmatically

使用9个补丁图像作为标签指示器的实例,我在tab_selected.xml、tab_selected_focused.xml、tab_selected_pressed.xml、tab_unselected.xml、tab_unselected_focused.xml和tab_unselected_pressed.xml中使用了布局列表。

tab_selected.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

<item>
    <shape android:shape="rectangle" >
    <solid android:color="#ffffff" />

    <padding android:bottom="2dp" />
    </shape>
</item>
<item>
    <shape android:shape="rectangle" >
        <solid android:color="@color/actionbar_color" />
    </shape>
</item>

tab_selected_pressed.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <shape android:shape="rectangle" >
            <solid android:color="@color/actionbar_color" />
        </shape>
  </item>
</layer-list>

tab_selected_focused.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <shape android:shape="rectangle" >
            <solid android:color="@color/actionbar_color" />
        </shape>
  </item>
</layer-list>

tab_unselected.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >


    <item>
        <shape android:shape="rectangle" >
            <solid android:color="@color/actionbar_color" />
        </shape>
    </item>

</layer-list>

tab_selected_unfocused.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <shape android:shape="rectangle" >
            <solid android:color="@color/actionbar_color" />
        </shape>
  </item>
</layer-list>

tab_selected_unselected.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <shape android:shape="rectangle" >
            <solid android:color="@color/actionbar_color" />
        </shape>
  </item>
</layer-list>

谢谢

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-04
    • 1970-01-01
    • 2014-11-12
    • 2018-02-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多