36

Here's what I'd like to remove :

enter image description here

How do I replace the indicator showing which tab is currently shown as well as the blue line that spans the entire tabwidget?

To Specify: All I want indicating which tab is selected is this :

  • tab_button_active.9.png should be shown as background if the tab is SELECTED
  • tab_button_inactive.9.png should be shown as the background if the tab is NOT SELECTED.

edit : Setting tabStripEnabled to false has no effect. Adding a style to it and having "@android:style/Widget.Holo.ActionBar" as its parent is also not possible since im targetting API level 7 and the ActionBar was implemented in API level 11.

CodePrimate
  • 6,646
  • 13
  • 48
  • 86
  • Did you try this stackoverflow post: http://stackoverflow.com/questions/10240756/android-how-to-remove-selected-tab-highlight-color-on-press-highlight-on-tabw – f20k Mar 07 '13 at 16:33
  • You can customize everything about the actionbar. There is a good tutorial [here.](http://android-developers.blogspot.it/2011/04/customizing-action-bar.html) And a similar question [here.](http://stackoverflow.com/a/14589743/2015318) – StarsSky Feb 03 '13 at 12:14

18 Answers18

45

This line app:tabIndicatorHeight="0dp" solve the problem for me in xml

 <android.support.design.widget.TabLayout
        android:id="@+id/view_bottom_tabLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabIndicatorHeight="0dp"             //this line
        app:tabGravity="fill"
        app:tabMode="fixed" />
SaravanaRaja
  • 3,228
  • 2
  • 21
  • 29
41

I have yet another hack.

    TabLayout tabLayout = (TabLayout) fragmentView.findViewById(R.id.tabs);
    tabLayout.setSelectedTabIndicatorHeight(0);

It's basically the same idea as Eleojasmil's.

Bart Burg
  • 4,786
  • 7
  • 52
  • 87
17

If android:tabStripEnabled="false" did not work then I also assume calling setStripEnabled(boolean stripEnabled) will have no effect as well. If all of this is true then your problem is probably not in TabWidget.

I would suggest looking at your tab indicator. Try these modifications. This code is taken from a fragment that has tabs.

Here is the code that creates the tab indicator view.

    View indicator = LayoutInflater.from(getActivity()).inflate(R.layout.tab,
(ViewGroup) mRoot.findViewById(android.R.id.tabs), false);

        TabSpec tabSpec = mTabHost.newTabSpec(tag);
        tabSpec.setIndicator(indicator);
        tabSpec.setContent(tabContentId);

Your tab indicator view would probably like similar to this.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center"
    android:layout_weight="1"
    android:background="@drawable/tabselector"
    android:padding="5dp" >

    <ImageView
        android:id="@+id/icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/tab1icon"/>

</LinearLayout>

Now the important part here is the android:background="@drawable/tabselector" in the LinearLayout. Mine looks like this.

<?xml version="1.0" encoding="utf-8"?>
<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="@drawable/tab_unselected_light" />
    <item
        android:state_focused="false"
        android:state_selected="true"
        android:state_pressed="false"
        android:drawable="@drawable/tab_selected_light" />
    <!-- Focused states -->
    <item
        android:state_focused="true"
        android:state_selected="true"
        android:state_pressed="false"
        android:drawable="@drawable/tab_focused_light" />
    <!-- Pressed state -->
    <item
        android:state_pressed="true"
        android:drawable="@drawable/tab_pressed_light" />
</selector>

This tabselector.xml is where you will swap @drawable/tab_pressed_light with your @drawable/tab_button_active and @drawable/tab_unselected_light with @drawable/tab_button_inactive

Be sure to check that all of your drawables that go into your tabselector.xml do not have the blue strips along the bottom. As I look at your image I can see little 5px gaps along that strip this is what gave me the idea that the strip was not from your TabWidget. Hope this helps.

ericharlow
  • 2,045
  • 3
  • 21
  • 26
  • 2
    android:tabStripEnabled="false" was not available for me. I instead had to use app:tabIndicatorHeight="0dp" – pyRabbit Mar 09 '17 at 14:46
17

For TabLayout: Just Use app:tabIndicatorColor="@android:color/transparent"

<android.support.design.widget.TabLayout
        android:id="@+id/profile_album_tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:animateLayoutChanges="true"
        android:theme="@style/AppTheme.AppBarOverlay"
        app:tabBackground="@drawable/tab_background"
        app:tabIndicatorColor="@android:color/transparent"
        app:tabPadding="@dimen/common_margin" />
Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
9

Add this to your TabLayout XML:

app:tabIndicator="@null"
double-beep
  • 5,031
  • 17
  • 33
  • 41
Catalin
  • 109
  • 1
  • 2
7

there is one line answer to that you have only to change the color of the indicator into a transparent

color.xml

 <color name="transparent2">#00000000</color>

and put this line to your tabwidget

tabLayout.setSelectedTabIndicatorColor(getResources().getColor(R.color.transparent2));

or

app:tabIndicatorColor="@color/transparent2"
Eleojasmil J Milagrosa
  • 1,944
  • 1
  • 13
  • 15
6

Try setting the Tab indicator height to zero:

tabLayout.setSelectedTabIndicatorHeight(0);
Viral Patel
  • 32,418
  • 18
  • 82
  • 110
Code mx
  • 61
  • 1
  • 5
4

Use tabLayout.setSelectedTabIndicator(0).

tabLayout.setSelectedTabIndicatorHeight(0) is now deprecated and tabLayout.setSelectedTabIndicatorColor(Color.TRANSPARENT) won't perform as well because it uses transparency.

Dan Bray
  • 7,242
  • 3
  • 52
  • 70
4

Use this app:tabIndicator="@null"

<com.google.android.material.tabs.TabLayout
    android:id="@+id/tab_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:tabGravity="fill"
    app:tabIndicator="@null"
    app:tabMode="fixed" />
Reyaz Ahmad
  • 121
  • 3
3

Use

    tabLayout.setSelectedTabIndicator(null);

This will set the selected indicator drawable to null.

2

Set attribute android:tabStripEnabled="false" for your TabWidget.

Swayam
  • 16,294
  • 14
  • 64
  • 102
2

I looked for a long time to remove the ugly holo menu bar tried everything. accidentally used this code for another reason and it thank god removed it.

    for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {          
        tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#FF0000")); // unselected
        TextView tv = (TextView)tabhost.getTabWidget().getChildAt(i).findViewById(android.R.id.title); //Unselected Tabs
        tv.setTextColor(Color.parseColor("#ffffff"));
    }

Source: Android tabhost change text color style

Community
  • 1
  • 1
ThaLioN
  • 53
  • 6
2

You can simply use this method on your tablayout to hide the tab indicator.

tabLayout.setSelectedTabIndicatorColor(Color.TRANSPARENT);
1

here what I use, since the tabIndicator.setSelectedTabIndicatorHeight(0); is depcrecated

use tabIndicator.setSelectedTabIndicator(0);

this.girish
  • 1,296
  • 14
  • 17
1

For the best setting app:tabIndicatorHeight="0dp" worked for me.

Maulik Togadiya
  • 594
  • 5
  • 10
0

Use app:tabIndicatorColor="@color/transparent_color", it'll work 100%

Ashish Choudhary
  • 444
  • 1
  • 4
  • 11
-1

I assume you are using ActionBarSherlock. The problem with using a TabWdiget is, that it is not part of ABS, so it will look "native" for each Android Version. For me, the best approach for tab navigtion with ABS is to use a ViewPager and ViewPagerIndicator and style the indicator. Downside is, that your tabs must be fragments. If you need your tabs to be activities then you should take a look if the guys at HoloEveryhwhere have managed to add the TabWidget.

stoilkov
  • 1,686
  • 1
  • 11
  • 18
-2
tabHost.getTabWidget().setStripEnabled(false);
tabHost.getTabWidget().getChildAt(1).setBackgroundColor(getResources().getColor(R.color.tabcolor));
tabHost.getTabWidget().getChildAt(2).setBackgroundColor(getResources().getColor(R.color.tabcolor));

More info here

Diligent Key Presser
  • 4,183
  • 4
  • 26
  • 34