【问题标题】:Android AppBarLayout with tabs and ViewPager带有标签和 ViewPager 的 Android AppBarLayout
【发布时间】:2019-08-08 12:06:27
【问题描述】:

我的应用有一个非常奇怪的问题。我有带有标签的AppBarLayoutViewPager。我已经为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" />

父布局:

<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】:

寻找下面的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"

【讨论】:

  • 这个我试过了,可惜没用。
  • 只有当我使用带有片段的视图寻呼机时才会发生这种情况,它似乎与 onTabSelected 事件有关。
猜你喜欢
  • 2019-02-03
  • 2012-11-17
  • 2015-11-21
  • 1970-01-01
  • 1970-01-01
  • 2015-12-15
  • 1970-01-01
  • 1970-01-01
  • 2016-08-11
相关资源
最近更新 更多