How to make toolbar fixed while scrolling in android?

M.Yogeshwaran picture M.Yogeshwaran · Feb 8, 2017 · Viewed 11.9k times · Source

I have researched all the previous question before posting this question none of the previous solution worked for me. I need to make my Toolbar static while scrolling it goes up while scrolling butI need to make it static how can i do this. Now let me explain what are all the methods I have tried so far,

  1. I have entered windowSoftInputMode to adjust resize

  2. fitwindows true in layout

This is the code i have written :

This is the main CoordinatorLayout:

<?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"
    android:id="@+id/main_content"
    android:fitsSystemWindows="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <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/ThemeOverlay.AppCompat.Light"
            app:layout_scrollFlags="scroll|enterAlways" />
    </android.support.design.widget.AppBarLayout>

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



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

This is the layout file :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_incident"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">
    <android.support.v7.widget.RecyclerView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/incident_recyclerview"
        android:divider="#fff"
         android:keepScreenOn="true"
        android:dividerHeight="0.5dp"
        />
</RelativeLayout>

I just want to make my Toolbar static how can I achieve Thanks in advance!!

Answer

Jd Prajapati picture Jd Prajapati · Feb 8, 2017

Remove app:layout_scrollFlags="scroll|enterAlways" this from Toolbar and check scroll.