如何在 Web 视图中向下滚动时隐藏操作栏/工具栏 [英] How to Hide ActionBar/Toolbar While Scrolling Down in Webview
问题描述
在 Google chrome 和 Play 商店中.该应用程序可以在滚动时隐藏操作栏,并允许用户方便地浏览.请帮助我这样做.
In Google chrome and play store. the app can hide the actionbar while scrolling and allows the user to Browse conveniently. Please Help me to do like this.
我已经将 onTouchListener 用于 webview,但它不起作用.
I've used onTouchListener for webview it doesn't works.
mWebView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
getSupportActionBar().show();
break;
case MotionEvent.ACTION_UP:
getSupportActionBar().hide();
break;
default: break;
}
return false;
}
});
提前致谢
推荐答案
您可以使用设计库的 CoordinatorLayout
和 NestedScrollView
和 在没有任何 Java 代码的情况下做到这一点>app:layout_scrollFlags
在 Toolbar
上设置.这是你如何做到的.
You can do this without any Java code using the design library's CoordinatorLayout
and NestedScrollView
, with app:layout_scrollFlags
set on Toolbar
. Here's how you do it.
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<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"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_vertical"
android:fillViewport="true"
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.support.design.widget.CoordinatorLayout>
一旦掌握了它,您就可以尝试使用不同的 layout_scrollFlags 和 fitsSystemWindows 行为.
You can play around with with different layout_scrollFlags and fitsSystemWindows behaviour once you get the hang of it.
这篇关于如何在 Web 视图中向下滚动时隐藏操作栏/工具栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!