【发布时间】:2010-06-24 17:25:42
【问题描述】:
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?
【问题讨论】:
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?
【问题讨论】:
这就是我所拥有的:
//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.xml 添加到res/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>
我从联系人应用程序 GIT 存储库下载了图标。:
git://android.git.kernel.org/platform/packages/apps/Contacts.git
【讨论】:
getResources().getDrawable(R.drawable.your_xml_file); 我的选项卡中没有文本,也没有使用意图这就像一个魅力。