Coder123
Coder123

Reputation: 31

Hide toolbar on RecyclerView scroll causes text to move into notification bar

In an application I am just starting, I have a RecyclerView. I used the following code to hide the toolbar when scrolling through the RecyclerView:

app:layout_scrollFlags="scroll|enterAlways"

When scrolling, the toolbar moves but it's text slides into the notification tray instead of disappearing.

At the top of the image in the notification tray it says HarHar and then shows the settings button at the end.

An example of this is:

Image of toolbar in notification tray

The code for the toolbar is:

 <?xml version="1.0" encoding="utf-8"?>
<android.support.design.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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.harhar.harhar.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay"
            app:layout_scrollFlags="scroll|enterAlways"
            />

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

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

    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        android:src="@android:drawable/ic_dialog_email" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerList"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        />`

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

If anyone could help I would truly appreciate it. Thank you.

 if (canHelpMe()){
        eternallyGrateful();
    }else if(needExtraInformation()){
        letMeKnow();
    }else{
        reallySad();
    }

Upvotes: 2

Views: 677

Answers (2)

Sandy
Sandy

Reputation: 1005

Hi Remove android:fitsSystemWindows="true" from the CoordinatorLayout.

So your CoordinatorLayout look like this

e.g.

<android.support.design.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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.harhar.harhar.MainActivity">

Let me know if issues still persist

Upvotes: 2

Ricky Patel
Ricky Patel

Reputation: 465

adding one toolbar layout in different XML file and then include that XML file it work, or remove app:layout_scrollFlags="scroll|enterAlway

<android.support.v7.widget.Toolbar 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"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    app:popupTheme="@style/AppTheme.PopupOverlay">

</android.support.v7.widget.Toolbar>

Upvotes: 3

Related Questions