如何在TabLayout(Android设计支持库)中更改下划线的长度

问题描述 投票:0回答:3

我正在使用Tablayout + ViewPager作为UI框架。 tablayout中有一个选定标签的下划线。文本长度和下划线长度不相等。我想要它们相等如何做到这一点?非常感谢

android android-layout
3个回答
1
投票

您可以像下面一样更改tabIndicator的颜色和高度

<android.support.design.widget.TabLayout
android:id="@id/pages_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorColor="@android:color/white"
app:tabIndicatorHeight="4dp"/>

AFAIK您将标签指示器长度设置为其标签宽度,如果您确实要更改,则无法仅更改指示器尺寸尝试更改tabWidth因此指示器也会随此更改而变化。

app:tabMaxWidth="30dp"

0
投票
app:tabMinWidth="210dp"
app:tabMaxWidth="110dp"

在XML中只添加这两行代码。它取决于您的标签项。您可以一次修改只增加和减少。


-2
投票

您可以在选项卡布局上添加另一个布局并相应地填充。

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:layout_below="@+id/toolbar"
        android:id="@+id/tabLayout"
        android:background="@color/colorTangerine">

    <com.techlabs.oodhaar.views.CustomTabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabBackground="@color/colorTangerine"
        app:tabIndicatorColor="@color/colorBackground"
        app:tabSelectedTextColor="@color/colorBackground"
        app:tabTextColor="@color/colorBackground"
        app:tabIndicatorHeight="4dp"
        />
    </RelativeLayout>
© www.soinside.com 2019 - 2024. All rights reserved.