Android Material 带圆角的选项卡布局指示器

Android Material Tab Layout indicator with round corners

如何制作 material 带有圆角的选项卡布局指示器

参考图片

使用此 app:tabIndicator 属性 自定义选项卡指示器。

像下面这样创建可绘制对象

indicator.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <corners android:topRightRadius="5dp"
                android:topLeftRadius="5dp"/>
            <solid android:color="@color/color_text_black" />
        </shape>
    </item>
</layer-list>

使用上面 XML 像下面这样

app:tabIndicator="@drawable/indicator"