views:

32

answers:

2

I have a tabhost with icon, when a tab is selected X, the icon does not appear because the icon is the same color as the selected tab. The question is:

How do I change the icon, when a tab is selected X?

+1  A: 

Is this what you are trying to achieve?

http://stackoverflow.com/questions/773690/android-customizing-tabs-on-state-how-do-i-make-a-selector-a-drawable

Barry
yes! Thank you very much Barry!!!!
Pedro
+1  A: 

This is what I have:

//TabActivity.onCreate()
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;

intent = new Intent().setClass(this, YourClass.class);
spec = tabHost.newTabSpec("tab_name").setIndicator("Tab Text",
            getResources().getDrawable(R.drawable.ic_tab_dialer))
            .setContent(intent);
tabHost.addTab(spec);

Then, you need to add ic_tab_dialer.xml to res/drawable/ directory with this content:

<selector xmlns:android="http://schemas.android.com/apk/res/android"&gt;
    <item android:state_selected="true"
        android:state_pressed="false"
        android:drawable="@drawable/ic_tab_selected_dialer" />
    <item android:drawable="@drawable/ic_tab_unselected_dialer" />
</selector>

I downloaded the icons from Contacts app GIT repo.:

git://android.git.kernel.org/platform/packages/apps/Contacts.git

licorna