简体   繁体   English

使WebView上的工具栏折叠向上和向下滚动

[英]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. 如何在滚动webview下方时使工具栏隐藏和显示。 Here is my Layout. 这是我的布局。 I already tried to make the webview a scroll container and nothing happened. 我已经尝试将webview设置为滚动容器,但没有任何反应。

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

Put the WebView inside a NestedScrollView and add this property: WebView放在NestedScrollView并添加此属性:

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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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