0

我已经实现了一个带有 recylerview 的工具栏,就像在博客文章中一样。但我还添加了一个导航抽屉。如果我执行以下步骤,工具栏在滚动后再次进入时变为白色

  1. 向下滚动,RecyclerView所以Toolbar会隐藏
  2. NavigationDrawer向左滑动打开
  3. 关闭NavigationDrawer右关闭
  4. 向上滚动RecyclerView
  5. Toolbar在这个变白之后出现

我知道工具栏仍然存在,因为我仍然可以单击其中膨胀的菜单项。当我单击工具栏中的汉堡包图标时,它再次变为原始颜色。

这是结果如何的图像 图片

这是我在代码中实现它的方式

工具栏.xml

 <?xml version="1.0" encoding="utf-8"?>
    <android.support.v7.widget.Toolbar
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/my_awesome_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:background="?attr/colorPrimary"
        android:minHeight="?attr/actionBarSize"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>

activity_main.xml

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/drawer_layout"
    >

    <android.support.design.widget.CoordinatorLayout
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        >

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

           <include layout="@layout/toolbar"/>

        </android.support.design.widget.AppBarLayout>

      <FrameLayout
          android:id="@+id/container"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          app:layout_behavior="@string/appbar_scrolling_view_behavior"/>



    </android.support.design.widget.CoordinatorLayout>


        <fragment
            android:id="@+id/navigation_drawer"
            android:name="aungkyawpaing.yangonuniversity.Fragments.NavigationDrawerFragment"
            android:layout_width="@dimen/navigation_drawer_width"
            android:layout_height="match_parent"
            android:layout_gravity="start|left"
            tools:layout="@layout/fragment_navigation_drawer"/>

</android.support.v4.widget.DrawerLayout>
4

2 回答 2

1

我正在使用库 23.3.0。并且错误仍然存​​在。

解决方法是添加几乎不占用空间且不可见的视图。请参阅下面的结构。

<android.support.v4.widget.NestedScrollView
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

</android.support.v4.widget.NestedScrollView>

<android.support.design.widget.AppBarLayout>

    <android.support.v7.widget.Toolbar
        app:layout_scrollFlags="scroll|enterAlways" />

    <android.support.design.widget.TabLayout
        app:layout_scrollFlags="scroll|enterAlways" />

    <View
        android:layout_width="match_parent"
        android:layout_height=".3dp"
        android:visibility="visible"/>

</android.support.design.widget.AppBarLayout>

有关更多详细信息,请参阅https://code.google.com/p/android/issues/detail?id=178037

于 2016-05-30T23:44:32.377 回答
0

这是设计库中的一个错误 https://code.google.com/p/android/issues/detail?id=178037

此错误已在 v22.2.1 中发布。

于 2015-08-03T07:53:08.580 回答