如何在工具栏下滚动 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/