1

I have a Tab Layout with two tabs in one of my projects. I was wondering if you can change the tab selection color (the pink line) and make it some other color.

here is the xml

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="#212121"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabMode="fixed"
        app:tabGravity="fill"
        android:background="#212121"/>
</android.support.design.widget.AppBarLayout>

<android.support.v4.view.ViewPager
    android:id="@+id/viewpager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

enter image description here

mremremre1
  • 1,036
  • 3
  • 16
  • 34
  • Check [this](http://stackoverflow.com/questions/18909273/how-to-change-color-of-selected-tab) – Faraz Dec 31 '15 at 14:39

2 Answers2

3

add this line to your tablayout...

<android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="#212121"
        app:layout_scrollFlags="scroll|enterAlways"
         app:tabIndicatorColor="@color/white"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

it will do the job.

riaz hasan
  • 1,155
  • 2
  • 8
  • 20
0

Define a selector and apply it to your TabLayout in the style :

<style name="Base.Widget.Design.TabLayout" parent="android:Widget">
    <item name="tabBackground">@drawable/tab_background</item>
</style> 
Helmi
  • 556
  • 2
  • 19