androiddroid androiddroid - 5 months ago 112
Android Question

Hiding toolbar in CoordinatorLayout after scrolling down

Here is my try for hiding

ToolBar
after Scrolling down:

<?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/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">

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

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


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

<WebView
android:layout_width="match_parent"
android:id="@+id/webview"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_height="match_parent">

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


I need to when
WebView
scrolling down, The
ToolBar
hided.

How we can do that?

As always, my style is:

Theme.AppCompat.Light.NoActionBar

Answer

Put WebView in NestedScrollView:

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

        <WebView
            android:id="@+id/web_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            />
    </android.support.v4.widget.NestedScrollView>

But, after thet, I have hardly scrolling on the horizontal axis. Please, post the comment if you find proper solution.

Comments