删除TabLayout当前Tab下的选择器行

Vir*_*uss 16 tabs android android-tablayout

我正在使用带有3个选项卡的TabLayout.我自定义了我的标签视图,因此,我需要在我的标签下删除以下行(截图不是来自我的应用):

在此输入图像描述

没有使用TabHost或TabWidget,因此我无法使用setStripEnabled(false).将背景设置为透明也不会改变任何东西.

这是我的xml:

<android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical" android:padding="4dip"
    android:layout_above="@+id/bottomcontent3"
    android:gravity="center_horizontal"
    android:background="@android:color/white"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.TabLayout
        android:id="@+id/comtabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        app:tabPaddingStart="0dp"
        app:tabPaddingEnd="0dp"
        app:tabMode="fixed"
        app:tabGravity="fill"
        android:background="@android:color/white" />

    <android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/compager"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </android.support.v4.view.ViewPager>

</android.support.design.widget.AppBarLayout>
Run Code Online (Sandbox Code Playgroud)

我找到的所有答案都在使用TabHost,TabWidget.就我而言,我正在使用一个TabLayout和三个Tab.在这种情况下如何删除此行?非常感谢.

编辑由于某些原因,我的代码无法解析TabLayout中的某些方法.有我使用的java代码:

TabLayout tabLayout = (TabLayout) view.findViewById(R.id.comtabs);
        tabLayout.setTabMode(TabLayout.MODE_FIXED);


        // add tabs
        tabLayout.addTab(tabLayout.newTab());
        tabLayout.addTab(tabLayout.newTab());
        tabLayout.addTab(tabLayout.newTab());

        RelativeLayout layout1 = (RelativeLayout) inflater.inflate(R.layout.communitytablayoutleft, container, false);
        RelativeLayout layout2 = (RelativeLayout) inflater.inflate(R.layout.communitytablayout, container, false);
        RelativeLayout layout3 = (RelativeLayout) inflater.inflate(R.layout.communitytablayoutright, container, false);
        tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);



        ViewPager pager = (ViewPager) view.findViewById(R.id.compager);
        CommunityPagerFragment adapter = new CommunityPagerFragment(getChildFragmentManager());

        pager.setAdapter(adapter);
        tabLayout.setupWithViewPager(pager);
        tabLayout.setOnTabSelectedListener(this);


        ((TextView)layout1.findViewById(R.id.tabtext)).setText(tabs[0]);
        ((TextView)layout2.findViewById(R.id.tabtext)).setText(tabs[1]);
        ((TextView)layout3.findViewById(R.id.tabtext)).setText(tabs[2]);



        tabLayout.getTabAt(0).setCustomView(layout1);
        tabLayout.getTabAt(1).setCustomView(layout2);
        tabLayout.getTabAt(2).setCustomView(layout3);
        //tabLayout.set

        return view;
Run Code Online (Sandbox Code Playgroud)

及其进口:

import android.support.design.widget.TabLayout;
Run Code Online (Sandbox Code Playgroud)

Vir*_*uss 36

正如两个答案所暗示的那样,关键是tabIndicatorHeight属性.

然而,由于某些原因,API的方法无法解决.在这种情况下,您必须直接从xml修复此问题,这样:

        app:tabIndicatorHeight="0dp"
Run Code Online (Sandbox Code Playgroud)

在你的<android.support.design.widget.TabLayout>布局中.

举个例子:

<android.support.design.widget.TabLayout
    android:id="@+id/comtabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="5dp"
    app:tabIndicatorHeight="0dp"
    app:tabPaddingStart="0dp"
    app:tabPaddingEnd="0dp"
    app:tabMode="fixed"
    app:tabGravity="fill"
    android:background="@android:color/white" />
Run Code Online (Sandbox Code Playgroud)


mys*_*yst 8

即使我最近遇到了同样的问题.我遇到了高度xml属性,并将其更改为0dp为我做了诀窍.

app:tabIndicatorHeight="0dp"
Run Code Online (Sandbox Code Playgroud)

要么

同样地,我觉得将指标的颜色属性更改为与选项卡的背景相同也应该这样做.我没有测试过这个解决方案,但我认为它也应该有效.

app:tabIndicatorColor="#9cc8df"
Run Code Online (Sandbox Code Playgroud)

第一个选择更好,它对我有用.

这些都不如实际禁用指标那样好,但无论如何都能解决问题.


Roh*_*man 6

我认为最好的解决方案是将选项卡指示器设置为空。

应用程序:tabIndicator="@null"


Sac*_*hin 5

对于TabLayout,您必须使用它-“ tabLayout.setSelectedTabIndicatorColor(Color.TRANSPARENT);

TabLayout tabLayout = (TabLayout) fragmentView.findViewById(R.id.tabs);
tabLayout.setSelectedTabIndicatorColor(Color.TRANSPARENT);
Run Code Online (Sandbox Code Playgroud)