Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Toolbar Collapse on WebView Scroll Up and Down

How can i make the Toolbar to hide and show while scrolling the webview under it. Here is my Layout. I already tried to make the webview a scroll container and nothing happened.

<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".StoreActivity">

<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:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    app:layout_scrollFlags="scroll|enterAlways"
    android:id="@+id/toolbar"
    android:background="#367e3d">

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

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

<WebView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/store"
    android:layout_below="@+id/appbar"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />
    </RelativeLayout>

1 Answers

Put the WebView inside a NestedScrollView and add this property:

app:layout_behavior="@string/appbar_scrolling_view_behavior"

Example:

<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/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</android.support.v4.widget.NestedScrollView>
like image 110
RiccardoCh Avatar answered Apr 24 '26 12:04

RiccardoCh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!