禁用Tablayout上的Material Ripple效果

36

我想要移除TabLayout选项卡上的Material Ripple Effect。

请问有可能实现吗?

如果有任何想法,请提出。

我已经尝试将stateListAnimator设置为null,但仍然没有起作用。

    <android.support.design.widget.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:stateListAnimator="@null"/>
6个回答

45

app:tabBackground在我的情况下无法工作。

这是我的解决方案:

tabLayout.setTabRippleColor(null);

1
你的答案需要更详细一些。https://stackoverflow.com/help/how-to-answer - Baptiste Mille-Mathias
欢迎来到 Stack Overflow!请尽可能详细地描述您的解决方案是如何工作的。参见:如何撰写优秀答案?。谢谢。 - sɐunıɔןɐqɐp
这个答案对我有用 - 在您的片段/活动中,您应该调用此函数来设置TabLayout。例如在Kotlin中 -                 val tabLayout = view.my_tab_layout             tabLayout.setupWithViewPager(mViewPager)             tabLayout.tabRippleColor = null - Jesson Atherton
2
你也可以在你的xml文件中使用<android.support.design.widget.TabLayout ... app:tabRippleColor="@null" - ArbenMaloku

33
将此行添加到XML中的TabLayout: app:tabRippleColor="@null"

17

尝试更改背景,例如使用android的透明颜色。

 <android.support.design.widget.TabLayout
    android:layout_width="match_parent"
    android:layout_below="@id/toolbar"
    android:layout_height="70dip"
    app:tabBackground = "@android:color/transparent"
    app:tabMode="fixed" />

8

只需将@null添加到tabRippleColor属性中即可。

 <com.google.android.material.tabs.TabLayout
            android:id="@+id/tabLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabRippleColor="@null" />  -> here

3

添加app:tabRippleColor属性

<com.google.android.material.tabs.TabLayout
     android:id="@+id/tabs"
     android:layout_width="match_parent"
     android:layout_height="48dp"
     app:tabRippleColor="@android:color/transparent"
     app:tabIndicatorColor="@android:color/transparent" />

在我的看法中,这比@null更适合在XML中使用。 - caly__pso

2

清晰易懂的代码

tabLayout.setTabRippleColorResource(android.R.color.transparent);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接