具有TabItem的材质TabLayout:波纹效果不起作用

焦日

在我的布局中,我在ViewPager上方有一个带有两个TabItem的TabLayout。一切都按预期工作,但是当我点击TabItem切换可见片段时,我没有涟漪效应。这是我的布局:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <com.google.android.material.tabs.TabLayout
        android:id="@+id/tab_layout"
        style="@style/Widget.MaterialComponents.TabLayout"
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:background="@color/white"
        app:tabBackground="@color/tab_bg_color"
        app:tabSelectedTextColor="@color/tab_sel_color"
        app:tabTextColor="@color/tab_text_color">

        <com.google.android.material.tabs.TabItem
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="TAB ONE" />

        <com.google.android.material.tabs.TabItem
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="TAB TWO" />

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


    <androidx.viewpager.widget.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

</LinearLayout>

这是我的PagerAdapter实现

 class UploadScreenPagerAdapter(fragmentManager: FragmentManager) : 
     FragmentPagerAdapter(
            fragmentManager,
            BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
     ) {
         var fragOne = FragOne()
         var fragTwo = FragTwo()

         override fun getItem(position: Int): Fragment {
             return when (position) {
                 0 -> fragOne
                 1 -> fragTwo
                 else -> fragOne
             }
        }

        override fun getCount(): Int {
            return 2
        }

        override fun getPageTitle(position: Int): CharSequence? {
            return when (position) {
                0 -> "TAB ONE"
                1 -> "TAB TWO"
                else -> ""
            }
        }
    }

怎么了?

IntelliJ Amiya
  • 去掉 android:background="@color/white"

JAVA代码

无效setTabRippleColor(ColorStateList颜色)

XML代码

您可以尝试使用app:tabRippleColor在下面的TabLayout部分中添加

app:tabRippleColor="@color/colorPrimary"  // or add your Hex code

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

材质设计组件切换效果不起作用

来自分类Dev

为什么SlideUp效果在具有表行显示的div上不起作用

来自分类Dev

动画效果不起作用

来自分类Dev

脉动效果不起作用

来自分类Dev

UICollectionView 单元格的材质波纹效果

来自分类Dev

collect_不起作用。在标准评估模式中,引用和〜ing是否应该具有相同的效果?

来自分类Dev

ImageButton中的透明背景具有波纹效果?

来自分类Dev

如何获得具有波纹效果的按钮背景色

来自分类Dev

如何获得具有波纹效果的按钮背景色

来自分类Dev

材质设计的滚动技术不起作用

来自分类Dev

材质设计的滚动技术不起作用

来自分类Dev

XML中的波纹可绘制不起作用

来自分类Dev

TabLayout 中的方法 removeAllTabs() 不起作用

来自分类Dev

过渡效果不起作用的jQuery

来自分类Dev

jQuery onmouseover效果不起作用

来自分类Dev

爆炸效果jQuery不起作用

来自分类Dev

对jQuery的缓解效果不起作用

来自分类Dev

jQuery的显示效果不起作用

来自分类Dev

Treeview拖放效果不起作用

来自分类Dev

FontAwesome悬停效果不起作用

来自分类Dev

对伪元素的悬停效果不起作用

来自分类Dev

UIMotionEffect的视差效果不起作用

来自分类Dev

为什么onMouseOver效果不起作用?

来自分类Dev

转盘滚动效果不起作用

来自分类Dev

LongListSelector Turnstile效果不起作用

来自分类Dev

链接上的悬停效果不起作用

来自分类Dev

组合悬停效果不起作用

来自分类Dev

jQuery UI盲效果不起作用

来自分类Dev

关于悬停效果不起作用