当选择标签X时,如何更改图标?

Ped*_*dro 2 android android-tabhost

我有一个带有图标的tabhost,当选择一个标签X时,图标不会出现,因为该图标与所选标签的颜色相同.问题是:

当选择标签X时,如何更改图标?

lic*_*rna 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);
Run Code Online (Sandbox Code Playgroud)

然后,您需要使用以下内容添加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>
Run Code Online (Sandbox Code Playgroud)

我从联系人应用程序GIT仓库下载了图标:

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