白色 tabLayout 的波纹效果

Ripple effect on white tabLayout

android 选项卡上的涟漪效果默认为白色。我想在 tablayout 上添加涟漪效果,但我的标签背景已经是白色,涟漪效果在上面是不可见的。

 <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:layout_gravity="end"
            android:layout_weight="1"
            android:background="@color/white"
            app:layout_collapseMode="pin"
            app:tabMode="fixed"
            app:tabIndicatorColor="@color/colorPrimary"
            app:tabBackground="?attr/selectableItemBackground"
            app:tabSelectedTextColor="@color/colorPrimary"
            app:tabTextColor="#222"
            />

有没有办法改变 tabLayout 波纹效果的颜色,使其即使在白色背景下也能看到?

您需要在 TabLayout 标签中使用 app:tabBackground 设置背景。

<android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabBackground="@drawable/tab_selector_ripple">

tab_selector_ripple.xml

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="#0e0e0e">
    <item android:drawable="@color/white" />

</ripple>

如果您对此有更多疑问,请告诉我?