美文网首页
com.google.android.material.tabs

com.google.android.material.tabs

作者: lllllittlep | 来源:发表于2020-12-03 14:29 被阅读0次

    <com.google.android.material.tabs.TabLayout

        android:id="@+id/tabLayout"

        android:layout_width="match_parent"

        android:layout_height="40dp"

        android:background="@color/colorPrimary"

        app:layout_constraintTop_toBottomOf="@+id/top"

        app:tabIndicatorHeight="2dp"

        app:tabIndicatorFullWidth="false"        //指示器宽度是否充满,fasle代表跟随文字宽度

     //如果想自定义圆角或者自定义宽度,使用drawable创建,drawable事例在下面 ①

        app:tabIndicator="@drawable/home_tab_indicator_shape" 

    如果想取消掉TabLayout选项卡点击时候的Ripple水波纹效果,直接给 app:tabRippleColor ="@android:color/transparent"null即可:

        app:tabRippleColor = "@android:color/transparent"

        app:tabMode="scrollable"

        app:tabSelectedTextColor="@color/color_white"

        app:tabTextColor="@color/color_white" />

    示例:①自定义的indicator drawable示例

    <?xml version="1.0" encoding="utf-8"?>

    <layer-list xmlns:android="http://schemas.android.com/apk/res/android"

        android:shape="rectangle">

        <item android:gravity="center">

                    android:width="20dp"

                    android:height="4dp" />

                <corners android:radius="20dp" />

                <solid android:color="@color/white" />

    </layer-list>

    那么如果想要在选中的时候改变选中大小呢

    只能通过自定义customView属性,去设置一个自定义的布局,然后监听选中事件,自己去手动设置选中或者未选中的样式

    不推荐反射的方式:效率慢,而且效果不能尽如人意

    以上应该能满足大部分开发中遇到的问题

    参考:

    https://my.oschina.net/u/4259809/blog/4330689

    https://blog.csdn.net/Liuyz0420/article/details/105439066/

    相关文章

      网友评论

          本文标题:com.google.android.material.tabs

          本文链接:https://www.haomeiwen.com/subject/rwtmwktx.html