开发者

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

开发者 https://www.devze.com 2023-01-04 11:00 出处:网络
I have a tabhost with icon, when a tab is selected X, the icon does not appear because the icon is the same c开发者_如何学运维olor as the selected tab. The question is:

I have a tabhost with icon, when a tab is selected X, the icon does not appear because the icon is the same c开发者_如何学运维olor as the selected tab. The question is:

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


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">
    <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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号