带有标签和ViewPager的Android AppBarLayout

问题描述 投票:0回答:1

我的应用程序有一个非常奇怪的问题。我有AppBarLayout标签和ViewPager。我为ViewPager配置了所有内容,页面正在点击选项卡,但是单击时标签上的涟漪效果(标签按钮)会中断。当我将TabLayout移出AppBarLayout时,问题消失了,当我将layout:paddingTop添加到AppBarLayout有时会出现波纹时,但除此之外,除了在当前选定的选项卡上之外,纹波没有正确显示。

AppBarLayout:

<com.google.android.material.appbar.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/app_bar_layout"
style="@style/Theme.appBarLayout">

<androidx.appcompat.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    style="@style/Theme.toolbar"
    app:layout_scrollFlags="scroll|snap"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:title="@string/app_name_text" />

<com.google.android.material.tabs.TabLayout
    android:id="@+id/home_tabs_layout"
    style="@style/Theme.tabs"
    app:tabIndicatorAnimationDuration="@android:integer/config_shortAnimTime"
    app:tabIndicatorColor="@color/primary_dark"
    app:tabIndicatorHeight="?attr/actionBarSize"
    app:tabMode="fixed"
    app:tabUnboundedRipple="false" />

ParentLayout:

<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
style="@style/Theme.home"
tools:context=".activities.HomeActivity">

<include
    layout="@layout/actionbar_tabbed"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

<androidx.appcompat.widget.FitWindowsLinearLayout
    style="@style/Theme.home.container">


    <androidx.viewpager.widget.ViewPager
        android:id="@+id/home_view_pager"
        style="@style/Theme.pager"
        android:layout_below="@id/home_tabs_layout" />

</androidx.appcompat.widget.FitWindowsLinearLayout>

我还试图用android studio中为ViewPager标签提供的预创建活动重现问题,行为是一样的。

先感谢您。

android android-viewpager ripple
1个回答
0
投票

查找以下xml代码

<com.google.android.material.tabs.TabLayout
            android:id="@+id/tabLayout"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:tabBackground="?attr/selectableItemBackgroundBorderless"
            app:tabGravity="fill"
            app:tabIndicatorHeight="0dp"
            app:tabMode="fixed"
            app:tabUnboundedRipple="true" />

请注意这两条线

app:tabBackground="?attr/selectableItemBackgroundBorderless" OR app:tabBackground="?attr/selectableItemBackground

app:tabUnboundedRipple="true"
© www.soinside.com 2019 - 2024. All rights reserved.