TabLayout 的底部指示线修改(固定长度,圆角)

最终效果

底部导航栏长度不再是填满,而是固定长度

显示圆角矩形

实现原理

隐藏 TabLayout 原生的 tabIndicator

      ...

        app:tabIndicatorHeight="0dp"

    .../>

1

2

3

4

替换 tabBackground

      ...

        app:tabBackground="@drawable/tab_selector"

    .../>

1

2

3

4

selector 代码

   

   

1

2

3

4

5

其中的选中 tab_selected 代码

   

   

       

           

       

   

   

   

        android:width="20dp"

        android:height="3dp"

        android:gravity="bottom|center_horizontal">

       

           

           

       

   

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

备注

原理是替换 tabBackground 的背景.

具体的替换drawable可以是 UI 设计,这里只是用 xml 简单的写了一个用于演示

测试发现这个xml写的drawable在 YunOs手机(魅族2)上失效

你可能感兴趣的:(TabLayout 的底部指示线修改(固定长度,圆角))