是的,没有自定义视图和外部库,这是可能的。。
您可以创建一个选择器文件
添加到可绘图文件夹
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:state_pressed="false">
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="-5dp" android:left="-5dp" android:right="-5dp" android:bottom="5dp">
<shape android:shape="rectangle">
<solid android:color="@android:color/white"/>
<stroke android:color="@color/colorPrimary" android:width="2dp"/>
</shape>
</item>
</layer-list>
</item>
<item android:state_selected="true" android:state_pressed="true">
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="-5dp" android:left="-5dp" android:right="-5dp" android:bottom="5dp">
<shape android:shape="rectangle">
<solid android:color="@android:color/white"/>
<stroke android:color="@color/colorPrimary" android:width="2dp"/>
</shape>
</item>
</layer-list>
</item>
</selector>
现在使用
app:tabBackground="@drawable/tab_indicator_line"
app:tabIndicatorHeight="0dp"
如果有任何疑问,请告诉我。。