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

Cod*_*ate 23 android

这是我要删除的内容:

在此输入图像描述

如何更换显示当前显示哪个选项卡的指示符以及跨越整个tabwidget的蓝线?

要指定:我想要指示选择哪个选项卡是:

  • 如果选项卡是SELECTED,tab_button_active.9.png应显示为背景
  • 如果选项卡未选中,tab_button_inactive.9.png应显示为背景.

编辑:将tabStripEnabled设置为false无效.添加样式并将"@android:style/Widget.Holo.ActionBar"作为其父级也是不可能的,因为我的目标API级别7和ActionBar是在API级别11中实现的.

Bar*_*urg 34

我还有另一个黑客.

    TabLayout tabLayout = (TabLayout) fragmentView.findViewById(R.id.tabs);
    tabLayout.setSelectedTabIndicatorHeight(0);
Run Code Online (Sandbox Code Playgroud)

这与Eleojasmil的想法基本相同.


Sar*_*aja 24

这行在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" />
Run Code Online (Sandbox Code Playgroud)


eri*_*low 15

如果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);
Run Code Online (Sandbox Code Playgroud)

您的标签指示器视图可能与此类似.

<?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>
Run Code Online (Sandbox Code Playgroud)

现在重要的部分是android:background="@drawable/tabselector"LinearLayout.我看起来像这样.

<?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>
Run Code Online (Sandbox Code Playgroud)

这tabselector.xml这里,您将交换@drawable/tab_pressed_light与你@drawable/tab_button_active@drawable/tab_unselected_light@drawable/tab_button_inactive

请务必检查进入tabselector.xml的所有drawable是否都没有底部的蓝色条带.当我看到你的图像时,我可以看到沿着那个条带的小5px间隙这就是让我觉得条带不是来自你的TabWidget的想法.希望这可以帮助.

  • android:tabStripEnabled ="false"不适用于我.我不得不使用app:tabIndicatorHeight ="0dp" (2认同)

Pra*_*ani 15

适用于TabLayout:只需使用app:tabIndicatorColor="@android:color/transparent"

<android.support.design.widget.TabLayout
        android:id="@+id/profile_album_tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:animateLayoutChanges="true"
        android:theme="@style/AppTheme.AppBarOverlay"
        app:tabBackground="@drawable/tab_background"
        app:tabIndicatorColor="@android:color/transparent"
        app:tabPadding="@dimen/common_margin" />
Run Code Online (Sandbox Code Playgroud)


小智 7

将此添加到您的TabLayout XML

app:tabIndicator="@null"
Run Code Online (Sandbox Code Playgroud)


Ele*_*osa 6

只有一行答案,您只需将指标的颜色更改为透明

color.xml

 <color name="transparent2">#00000000</color>
Run Code Online (Sandbox Code Playgroud)

并将此行添加到您的tabwidget

tabLayout.setSelectedTabIndicatorColor(getResources().getColor(R.color.transparent2));
Run Code Online (Sandbox Code Playgroud)

要么

app:tabIndicatorColor="@color/transparent2"
Run Code Online (Sandbox Code Playgroud)


小智 5

尝试将Tab指示器高度设置为零:

tabLayout.setSelectedTabIndicatorHeight(0);
Run Code Online (Sandbox Code Playgroud)

  • 干得好,重复我的回答:) (2认同)