0

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);
Uniruddh
  • 4,427
  • 3
  • 52
  • 86

1 Answers1

1

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

Community
  • 1
  • 1
Mehul Joisar
  • 15,348
  • 6
  • 48
  • 57
  • Thanks for the reference, i got this. And i have used `tab_indicator_holo.xml` in my project with green 9-patched images. But where to specify this drawable ? I'm using `FragmentTabHost`. – Uniruddh Apr 21 '14 at 10:57
  • @I-droid: post some code so that I can guide. you just need to add `tab_indicator_holo.xml` in your `drawable` directory and set it as background of each tab. – Mehul Joisar Apr 21 '14 at 11:22
  • @I-droid: I have added reference of example post. – Mehul Joisar Apr 21 '14 at 11:26
  • @MehulJosiar : Can you just explain `set it as background of each tab` ??? I mean, how to do this ? – Uniruddh Apr 21 '14 at 12:35