gpt4 book ai didi

android - 如何在 Webview 中向下滚动时隐藏操作栏/工具栏

转载 作者:IT老高 更新时间:2023-10-28 23:26:38 29 4
gpt4 key购买 nike

在 Google chrome 和 Play 商店中。该应用程序可以在滚动时隐藏操作栏,并允许用户方便地浏览。请帮我这样做。

我在 webview 中使用了 onTouchListener,它不起作用。

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;
}
});

提前致谢

最佳答案

您无需任何 Java 代码即可使用设计库的 CoordinatorLayoutNestedScrollView 并在 Toolbar 上设置 app:layout_scrollFlags 。这是你如何做到的。

<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 和 fitSystemWindows 行为。

关于android - 如何在 Webview 中向下滚动时隐藏操作栏/工具栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28770530/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com