android - 使工具栏在 WebView 上下滚动时折叠

标签 android webview material-design android-appbarlayout

如何在工具栏下滚动 webview 时隐藏和显示工具栏。这是我的布局。 我已经尝试使 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>

最佳答案

WebView 放入 NestedScrollView 并添加此属性:

app:layout_behavior="@string/appbar_scrolling_view_behavior"

例子:

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

关于android - 使工具栏在 WebView 上下滚动时折叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35879223/

相关文章:

javascript - 使用响应式页面内容实现侧边栏

android - 将样式应用于警报对话框

flutter - 如何让抽屉插入内容而不是放在内容之上?

android - 将数据从 Activity 传递到 android 中的 fragment 不起作用

ios - 我可以在 native iOS WebView 中使用 Polymer 吗?

javascript - Flutter - 如何在 WebView 中获取 Javascript 回调?

cocoa - 如何共享 Safari 的 NSURLCache 存储?

android - 在android中单击时隐藏默认键盘

android - 无法在 45 秒内启动 Intent。也许主线程在合理的时间内没有空闲?

android - 如何制作启动器