0

So i have been learning a tutorial to hide tool bar in CoordinatorLayout while i scroll up my view pagers first fragment but toolbar is not moving up or hiding while i scroll up.

The toolbar is added in Coordinator layout using < include layout / > tag.

But when i add tool bar directly whithout referencing it using < include layout / > (adding toolbar in Coordinator layout the way we add. DEFAULT WAY) the toolbar slides up and works.

Here is both .xml code, i dont understand why Coordinator Layout is not working with < include/> tag ?

Coordinator With include...

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

    <include
        layout="@layout/toolbar_main"
        android:id="@+id/toolbar"
        app:layout_scrollFlags="scroll|enterAlways" />

Toolbar is not responding to scroll BUT

Coordinator without custom Toolbar..

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

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

It WORKS! O.O BUT HOW ? And why < include tag is not working ?

here is my custom toolbar_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
/>
Mr.PooP
  • 15
  • 4

1 Answers1

0

Try moving the line

app:layout_scrollFlags="scroll|enterAlways"

to inside toolbar_main.xml instead of the include statement

Venu G.
  • 417
  • 1
  • 3
  • 10
  • Thanks, It actually is working now. just dont know why it is not working when i use it in < include tag. i read it that you can use custom xml with < include tag and if you add any extra attributes to < include, it will still work the same as it works without it. ¯\_(ツ)_/¯ – Mr.PooP Aug 23 '18 at 04:38