Remove ActionBar Tab from Android

0

By% with_% the ActionBar tabs come with the blue indicator (how much is selected) and my question is how do I remove this blue indicator.

I want to use icons in these tabs, but as the icon and blue indicator appear, I want to remove the indicator. I'm using style Holo

    
asked by anonymous 01.09.2014 / 16:07

1 answer

1

Removing the indicator is not easy.

The background of Tab of ActionBar is styled like this:

<?xml version="1.0" encoding="utf-8"?>
<!-- Licença, omitida por espaço -->

<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="@color/transparent" />
    <item android:state_focused="false" android:state_selected="true"  android:state_pressed="false" android:drawable="@drawable/tab_selected_holo" />

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

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

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

As you can see, there is a combination for each of the states: state_selected , state_focused and state_pressed .

The person responsible for placing the indicator is the status selected , so just remove the items that define this state.

    

<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="@color/transparent" />

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

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

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

I removed this drawable source code from the Android Holo Theme .

To stylize the entire tab is easy, just include an element in your theme, to reset the background of Tab .

<style name="AppTheme" parent="@android:style/Theme.Holo">
    <item name="actionBarTabStyle">@style/MyActionBarTabStyle</item>
    <item name="android:actionBarTabStyle">@style/MyActionBarTabStyle</item>
</style>

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

Now just create a file named my_tab_indicator_ab_holo.xml in the /res/drawable folder.

It is necessary to get the 9 patch images that are referenced in drawable and they are: list_focused_holo , list_pressed_holo_dark and tab_unselected_pressed_holo , because it is not possible to reference the internal resources of the platform. >

To do this, I used the Android source code on Github to get these drawables , the links are the following, the images are next:

  

HDPI Resolution :

     

-

    

-

     

-

    

MDPIResolution:

    

-

     

-

    

-

     

XHDPI Resolution :

     

-

    

-

     

-

    

XXHDPIResolution:

    

-

     

list_pressed_holo_dark.9.png -

    

-

Download these images and put in their folders: /res/drawable-hdpi , /res/drawable-mdpi , /res/drawable-xhdpi and /res/drawable-xxhdpi .

Unfortunately this is the only way I see styling, without losing the original background.

    
01.09.2014 / 16:56