Question

I want to change selection color of tab widget in my app. I Checked many answers & links but only able to change color of whole tab.

Following is what I want:

enter image description here

I want to change default blue selection color with green only. And not color of whole tab. What and how should i do in order to accomplish this ?

Edit : Following way i'm creating tabs.

    mTabHost.addTab(mTabHost.newTabSpec("Contacts").setIndicator("Contacts"), ContactFragment.class, null);
    mTabHost.addTab(mTabHost.newTabSpec("Favorite").setIndicator("Favorite"), FavoriteFragment.class, null);
    mTabHost.addTab(mTabHost.newTabSpec("Group").setIndicator("Group"), GroupFragment.class, null);
Was it helpful?

Solution

Just as an example, you can look into resources of android-sdk,

Suppose,

go to :

android-sdk-windows\platforms\android-19\data\res\drawable and look at file 

tab_bottom_right.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/tab_press_bar_right"/>
<item android:state_focused="false" android:drawable="@drawable/tab_selected_bar_right"/>
<item android:state_focused="true" android:drawable="@drawable/tab_focus_bar_right"/>

you can find associated 9 patch drawables in different folders.(hdpi,mdpi,xhdpi,etc) Suppose, go to:

android-sdk-windows\platforms\android-19\data\res\drawable-hdpi

and look for drawable named tab_press_bar_right.9.png

EDIT :

Have a look at following post : set selector drawable to tab

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top