【问题标题】:Android how to highlight drawable of selected action bar tabAndroid如何突出显示选定操作栏选项卡的drawable
【发布时间】:2014-07-18 19:59:47
【问题描述】:

我希望添加带有图标的操作栏选项卡。我已经实现了以下。

在此,如何使选定的选项卡图标变为橙色,即如果选择了第一个选项卡,则第一个图标为橙色,而其他图标保持灰色,依此类推。 谢谢

【问题讨论】:

标签: android android-xml android-tabs


【解决方案1】:

可能的解决方案是。您必须创建一个白色和橙色的图标并将其放入您的 drawables 文件夹中,并在您当前选项卡的 onCreate 方法中添加以下内容:

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

我希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多