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. 问题是:

选择选项卡时如何更改图标 X?

4

1 回答 1

16

这就是我所拥有的:

//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);

然后,您需要使用以下内容添加ic_tab_dialer.xmlres/drawable/目录:

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

我从 Contacts app GIT repo 下载了图标:

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

于 2010-06-24T17:41:02.463 回答