ToolbarLayout turns white on entering again

347 views Asked by At

I have implemented a toolbar with a recylerview just like in the blog post. But I have also added a navigation drawer. The toolbar turns white when it enter again after scrolling if I do the following steps

  1. Scroll Down The RecyclerView so the Toolbar would hide
  2. Open NavigationDrawer by Sliding Left
  3. Close NavigationDrawer by Closing Right
  4. ScrollUp the RecyclerView
  5. Toolbar which appears after this turn white

I know that Toolbar Is still there because I can still click on the menu item inflated in it. It turns to the original color again when I click on the Hamburger Icon in the Toolbar.

Here's is the image on how it turns out Image

Here's how I implemented it in code

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>
2

There are 2 answers

0
ali On

it is a bug in design library https://code.google.com/p/android/issues/detail?id=178037

this bug has been solve in Released in v22.2.1.

0
PravinDodia On

I'm using libraries 23.3.0. and the bug still occurs.

Workaround for this is adding View that takes nearly no space and can be invisible. See the structure below.

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

for more details please refer https://code.google.com/p/android/issues/detail?id=178037