简体   繁体   中英

Toolbar does not Hide/Shown on Scrolling in CoordinatorLayout

I'm trying to auto hide and show depends on scrolling of TextView implemented in ViewPager. But, Toolbar never hides on scrolling. Main XML activity_data_display.xml

<android.support.v4.widget.DrawerLayout 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/activity_drawer"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 tools:context="com.regio.developers.upasana.DataDisplayActivity">

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/activity_data_display"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bg">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <include
            android:id="@+id/toolbar"
            layout="@layout/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

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

    <android.support.v4.view.ViewPager
        android:id="@+id/data_viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

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

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

Here's the layout that is inflated in ViewPager data_swipe_layout.xml

<android.support.v4.widget.NestedScrollView
 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="wrap_content"
 app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/dataviewpager_textview"
        android:textColor="#FFF"
        android:paddingTop="20dp"
        android:paddingBottom="20dp"
        android:paddingRight="35dp"
        android:paddingLeft="35dp"
        android:textSize="20sp"
        android:gravity="center"/>

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

added Toolbar Layout file toolbar_layout.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/toolbar"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:background="?attr/colorPrimary"
 android:fitsSystemWindows="true"
 android:minHeight="?attr/actionBarSize"
 app:theme="@style/ToolBarStyle"
 app:layout_scrollFlags="scroll|enterAlways"
>

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

Please solve my problem?

I've tried different ways to make it work like using NestedScrollView in Main XML file. But, it just does not help.

Please try implementing yourself then give me solution for this.

Remember I've used TextView which contains hundreds of of line of text.

Also, how to implement ScrollBar which can be drag-able manually for the TextView in ViewPager?

You are using the included layout of toolbar you should make this property app:layout_scrollFlags="scroll|enterAlways"

for the AppBarLayout or write that code of toolbar in AppBarLayout.

Hope this helps.

Check this.
 it is working
<android.support.v4.widget.DrawerLayout 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/activity_drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<android.support.design.widget.CoordinatorLayout
    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:id="@+id/coordinatorLayout"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true">

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

    <android.support.v4.widget.NestedScrollView
        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="wrap_content"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/dataviewpager_textview"
            android:textColor="#FFF"
            android:paddingTop="20dp"
            android:paddingBottom="20dp"
            android:paddingRight="35dp"
            android:paddingLeft="35dp"
            android:textSize="20sp"
            android:text=""
            android:gravity="center"/>

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM