android " />

扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

Android中tablayout怎么设置tab背景

扬州沐宇科技
2024-05-28 09:15:11
android

要设置TabLayout的背景,可以通过设置TabLayout的background属性来实现。可以在xml文件中设置如下代码:

<android.support.design.widget.TabLayout
    android:id="@+id/tab_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimary"
    app:tabIndicatorColor="@color/colorAccent"
    app:tabIndicatorHeight="3dp"
    app:tabSelectedTextColor="@android:color/white"
    app:tabTextColor="@android:color/white"/>

在这个例子中,我们设置了TabLayout的背景颜色为colorPrimary,选中的tab的指示器颜色为colorAccent,选中的tab的文字颜色为白色,未选中的tab的文字颜色也为白色。你也可以根据自己的需要进行调整。

扫码添加客服微信