Jesper Martensson
Jesper Martensson

Reputation: 1248

How to change Color of the tabStrip in Android?

I am trying to change the color of my tabStrip to white, the code below is not working? What am I doing wrong ?

getTabHost().getTabWidget().setLeftStripDrawable(Color.WHITE);
getTabHost().getTabWidget().setRightStripDrawable(Color.WHITE);
getTabHost().getTabWidget().setStripEnabled(true);

Upvotes: 1

Views: 3925

Answers (3)

Navneet Kumar
Navneet Kumar

Reputation: 293

You can change the color with app:tabIndicatorColor="@color/indicator_color inside the Tablayout.

<android.support.design.widget.TabLayout
    app:tabIndicatorColor="@color/indicator_color
        />

Upvotes: 0

Swapnil Kadam
Swapnil Kadam

Reputation: 4293

i hope you want to change the color of the background of the tab strip. You could achieve this by creating a layout with a root element as

tab_strip.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.TabLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#FFFFFF">

</android.support.design.widget.TabLayout>

and in your xml where you are using tab, you could add the tab_strip.xml as follows

<include android:id="@+id/tab_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/toolbar"
        layout="@layout/tab_strip"/>

And this will make your tab strip colour to white.

Upvotes: 0

shriduttkothari
shriduttkothari

Reputation: 31

Use any drawable instead of color

means setLeftStripDrawable is requiring a drawable resource but you are giving int as a argument.

So either use a drawable image here. Or use a xml from drawable contaning the color.

Upvotes: 3

Related Questions