Android 删除表格布局的“当前”选项卡下的选择器行

Android 删除表格布局的“当前”选项卡下的选择器行,android,tabs,android-tablayout,Android,Tabs,Android Tablayout,我正在使用带有3个选项卡的表格布局。我自定义了选项卡的视图,因此,我需要删除选项卡下的以下行(屏幕截图不是来自我的应用程序): 我没有使用TabHost或TabWidget,因此我不能使用setTripEnabled(false)。将背景设置为透明也不会改变任何东西 以下是我的xml: <android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"

我正在使用带有3个选项卡的表格布局。我自定义了选项卡的视图,因此,我需要删除选项卡下的以下行(屏幕截图不是来自我的应用程序):

我没有使用TabHost或TabWidget,因此我不能使用
setTripEnabled(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>
及其进口:

import android.support.design.widget.TabLayout;

好像有API一样
void setselectedtabilicator颜色(int-color)

void setselectedTabidIndicator高度(整数高度)


您可以将选项卡指示器高度设置为0以“删除”它,例如使用:
tabLayout.setSelectedTabidIndicator高度(0)

正如两个答案所建议的,关键是
选项卡indicatorheight
属性

然而,由于某些原因,API中的方法无法解决。在这种情况下,您必须通过以下方式直接从xml解决此问题:

        app:tabIndicatorHeight="0dp"
布局中

例如:

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

对于表格布局您必须使用此-“表格布局.setSelectedTabIndicator颜色(Color.TRANSPARENT);


就连我最近也遇到了同样的问题。我遇到了height xml属性,并将其更改为0dp,这对我来说是个好办法

app:tabIndicatorHeight="0dp"

类似地,我觉得将指示器的颜色属性更改为与选项卡的背景相同也可以做到这一点。我还没有测试过这个解决方案,但我认为它也应该有效

app:tabIndicatorColor="#9cc8df"
第一种选择更好,而且对我很有效。


这些都不如实际禁用指示器好,但无论如何都能解决问题。

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

app:tabIndicator=“@null”


您正在使用Android支持设计库中的TabLayout吗?TabLayout TabLayout=(TabLayout)findViewById(R.id.tabs);然后表格布局。设置选定的标签或高度(0);这正是我所做的。仍然无法解决。让我把我的代码放在主要的帖子里,我找到了一种通过xml应用的方法。我会投票给你:)谢谢
SetSelectedTabidIndicatorHeight
在支持库28.0.0中被弃用:(尽管我无法解决这些方法,但仍然有效。让我用java代码编辑我的主要帖子,也许会有帮助。我找到了一种通过xml应用此功能的方法。我会投票给你:)谢谢!app:tabIndicatorColor=“@android:color/transparent”更简单。
app:tabIndicatorHeight="0dp"
app:tabIndicatorColor="#9cc8df"