Skip to content Skip to sidebar Skip to footer

Change Action Bar Tab Text Colour

I have an application which uses action bar with swipes. I have tabs with title like Tab1, Tab2, Tab3. I want to set different color of each of tab title. Tab1 (Red) Tab2(Blue) (Ta

Solution 1:

You can set a custom View for each tab. Create a new layout resource for the tab (it can just be a TextView). Leave its background empty and make a nine-patch drawable for the selection indicator. Get a LayoutInflater using

LayoutInflaterinflater= getSystemService(LAYOUT_INFLATER_SERVICE);

Then for each tab, you can do this:

Tabtab= ab.newTab()
    .setText("TY1")
    .setTabListener(newMyTabListener(this, TY1.class.getName()));
ViewtabView= inflater.inflate(R.layout.my_tab_layout, null);
tabView.setBackgroundColor(...); // set custom color
tab.setCustomView(tabView);
ab.addTab(tab);

If you want to create this manually, check This Post, and your problem will be solved.

Post a Comment for "Change Action Bar Tab Text Colour"