首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何从TabWidget中删除选中的选项卡指示器?

如何从TabWidget中删除选中的选项卡指示器?
EN

Stack Overflow用户
提问于 2013-02-03 20:09:31
回答 17查看 45K关注 0票数 32

下面是我想要删除的内容:

如何替换显示当前显示的选项卡的指示器以及横跨整个选项卡小部件的蓝线?

要指定:我只想指出选择了哪个选项卡:

如果选项卡是SELECTED

  • tab_button_inactive.9.png,则应将
  • tab_button_active.9.png显示为背景;如果未选中该选项卡,则应将其显示为背景。

编辑:将tabStripEnabled设置为false不起作用。向其添加样式并将"@android: style /Widget.Holo.ActionBar“作为其父对象也是不可能的,因为im的目标是API7,而ActionBar是在API11中实现的。

EN

回答 17

Stack Overflow用户

回答已采纳

发布于 2013-03-07 08:52:00

如果android:tabStripEnabled="false"不工作,那么我也假设调用setStripEnabled(boolean stripEnabled)也不会有任何效果。如果所有这些都是真的,那么您的问题可能不在TabWidget。

我建议你看看你的标签指示器。尝试这些修改。这段代码取自一个带有制表符的片段。

下面是创建选项卡指示器视图的代码。

    View indicator = LayoutInflater.from(getActivity()).inflate(R.layout.tab,
(ViewGroup) mRoot.findViewById(android.R.id.tabs), false);

        TabSpec tabSpec = mTabHost.newTabSpec(tag);
        tabSpec.setIndicator(indicator);
        tabSpec.setContent(tabContentId);

您的tab indicator视图可能类似于此。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center"
    android:layout_weight="1"
    android:background="@drawable/tabselector"
    android:padding="5dp" >

    <ImageView
        android:id="@+id/icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/tab1icon"/>

</LinearLayout>

现在这里最重要的部分是LinearLayout中的android:background="@drawable/tabselector"。我的是这样的。

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Non focused states -->
    <item
        android:state_focused="false"
        android:state_selected="false"
        android:state_pressed="false"
        android:drawable="@drawable/tab_unselected_light" />
    <item
        android:state_focused="false"
        android:state_selected="true"
        android:state_pressed="false"
        android:drawable="@drawable/tab_selected_light" />
    <!-- Focused states -->
    <item
        android:state_focused="true"
        android:state_selected="true"
        android:state_pressed="false"
        android:drawable="@drawable/tab_focused_light" />
    <!-- Pressed state -->
    <item
        android:state_pressed="true"
        android:drawable="@drawable/tab_pressed_light" />
</selector>

在这个tabselector.xml中,您可以将@drawable/tab_pressed_light@drawable/tab_button_active交换,将@drawable/tab_unselected_light@drawable/tab_button_inactive交换

请务必检查tabselector.xml中的所有可绘制部分是否没有底部的蓝色条带。当我看着你的图像时,我可以看到沿着那个条带的小5px的间隙,这就是为什么我认为这个条带不是来自你的TabWidget。希望这能有所帮助。

票数 17
EN

Stack Overflow用户

发布于 2015-11-17 00:04:48

我还有另一个技巧。

    TabLayout tabLayout = (TabLayout) fragmentView.findViewById(R.id.tabs);
    tabLayout.setSelectedTabIndicatorHeight(0);

这基本上与Eleojasmil的想法相同。

票数 41
EN

Stack Overflow用户

发布于 2016-01-28 22:06:34

下面这行app:tabIndicatorHeight="0dp"为我解决了xml中的问题。

 <android.support.design.widget.TabLayout
        android:id="@+id/view_bottom_tabLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabIndicatorHeight="0dp"             //this line
        app:tabGravity="fill"
        app:tabMode="fixed" />
票数 38
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14672302

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档