You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何移除Widget.Material3.TabLayout与指示器相邻的底部灰色分隔线

解决方案

你看到的灰色分隔线是Material3 TabLayout默认样式自带的底部边框,要移除它并仅保留蓝色指示器,可通过以下两种方式实现:

方法一:设置透明背景(最简单)

直接在你的自定义TabLayout样式中添加android:background属性并设为透明,即可去掉底部灰色线:

<style name="MyTabLayout" parent="Widget.Material3.TabLayout">
    <item name="tabTextColor">@color/black</item>
    <item name="tabSelectedTextColor">@color/black</item>
    <item name="tabIndicatorFullWidth">true</item>
    <!-- 移除底部灰色分隔线 -->
    <item name="android:background">@android:color/transparent</item>
</style>

方法二:自定义背景Drawable(需保留背景色时使用)

如果你的TabLayout需要设置特定背景色,同时去掉底部边框,可以自定义一个无stroke的shape Drawable:

  1. 在res/drawable/目录下创建tab_layout_bg.xml文件:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- 设置你需要的背景色 -->
    <solid android:color="@color/your_target_bg_color" />
    <!-- 不设置stroke属性,即无底部边框 -->
</shape>
  1. 在样式中引用该Drawable作为背景:
<style name="MyTabLayout" parent="Widget.Material3.TabLayout">
    <item name="tabTextColor">@color/black</item>
    <item name="tabSelectedTextColor">@color/black</item>
    <item name="tabIndicatorFullWidth">true</item>
    <!-- 使用自定义背景移除底部灰色线 -->
    <item name="android:background">@drawable/tab_layout_bg</item>
</style>

内容的提问来源于stack exchange,提问作者the_prole

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 07:20:14