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

发布于 2024-09-07 02:10:30 字数 91 浏览 0 评论 0原文

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

当选择选项卡 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. The question is:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墨小墨 2024-09-14 02:10:30

这就是我所拥有的:

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文