mremremre1
mremremre1

Reputation: 1036

Change the selection color of tabs in TabLayout

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

Upvotes: 1

Views: 1048

Answers (2)

Helmi
Helmi

Reputation: 556

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> 

Upvotes: 0

riaz hasan
riaz hasan

Reputation: 1155

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.

Upvotes: 3

Related Questions