1

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

Charuක
  • 12,953
  • 5
  • 50
  • 88
M.Yogeshwaran
  • 1,419
  • 4
  • 22
  • 48
  • Possible duplicate of [How to set my toolbar fixed while scrolling android](http://stackoverflow.com/questions/33506335/how-to-set-my-toolbar-fixed-while-scrolling-android) – Fragment Feb 08 '17 at 06:33
  • @M.Yogeshwaran you want to keep the tool bar in the same position or what does this mean again *need to make my tool bar static while scrolling it goes up while scrolling but i need to make it static* – Charuක Feb 08 '17 at 06:33
  • nothing to do with layout will i not work with coordinator layout – M.Yogeshwaran Feb 08 '17 at 06:34
  • @Charuක hello i don't want the toolbar moves it needs to be static – M.Yogeshwaran Feb 08 '17 at 06:35
  • Add Nested ScrollView after AppBarLayout it will work. – rohitanand Feb 08 '17 at 06:46

4 Answers4

6

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

Charuක
  • 12,953
  • 5
  • 50
  • 88
Jd Prajapati
  • 1,953
  • 13
  • 24
4

Okay there are lot of answers but ,

Is this what are you looking for?

enter image description here enter image description here

If yes, you can use CollapsingToolbarLayout

For the second view here is my xml all you need to remove ImageView to get the first view.

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                android:id="@+id/profile_id"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/monkey"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                app:layout_collapseMode="parallax" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin" />

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

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

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ffe5e5e5"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

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

        </LinearLayout>


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

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

Take a note that I've used app:layout_collapseMode="pin" for Toolbar

Have fun ^_^

Charuක
  • 12,953
  • 5
  • 50
  • 88
0

Make your layout like this. Your toolbar will be fixed at top while you scroll your layout.

<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:fitsSystemWindows="true"
    >

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed|enterAlwaysCollapsed"
        app:statusBarScrim="@color/primary"
        app:contentScrim="@color/primary"
        app:titleEnabled="false"
        app:layout_collapseMode="none"
        android:fitsSystemWindows="true">


        <!--
        we must create the value entry for the toolbar height here as different version would have different heights
        -->
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="top"
            android:gravity="top"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:contentInsetLeft="0dp"
            app:contentInsetStart="0dp">


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

    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
Umair
  • 6,366
  • 15
  • 42
  • 50
0
    <?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"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

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