gpt4 book ai didi

java - 防止重新加载 WebView onResume()

转载 作者:行者123 更新时间:2023-12-05 06:20:39 25 4
gpt4 key购买 nike

锁定我的屏幕并按下关闭按钮解锁后,我的 WebView 将重新加载。我发现问题出在 onResume()

@Override
protected void onResume() {
super.onResume();
mWebView.onResume();
mWebView.resumeTimers();
}

重新加载仅在 webview 中发生,因为我可以看到底部的导航栏未被触及。那么如何防止重新加载 webview 我将需要 onResume() 以供将来使用,因此删除不是解决方案。这是 Activity 布局

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="false"
android:windowTranslucentNavigation="false"
tools:context=".MainActivity">


<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipeRefresh"
android:layout_width="0dp"
android:layout_height="0dp"
android:overScrollMode="never"
android:soundEffectsEnabled="true"
app:layout_constrainedHeight="true"
app:layout_constrainedWidth="true"
app:layout_constraintBottom_toTopOf="@id/BottomLayout"
app:layout_constraintEnd_toEndOf="@id/BottomLayout"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:scrollbars="none"
android:visibility="gone" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

<include
android:id="@+id/netCon"
layout="@layout/network_connection" />

<include
android:id="@+id/srvCon"
layout="@layout/server_connection" />

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/BottomLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">

<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:animateLayoutChanges="true"
android:background="@drawable/border_top_bottom_menu"
android:clipToPadding="false"
android:duplicateParentState="false"
android:fitsSystemWindows="false"
android:focusableInTouchMode="false"
android:theme="@style/bottom_navigation_menu"
android:visibility="visible"
app:barrierAllowsGoneWidgets="true"
app:itemHorizontalTranslationEnabled="false"
app:itemIconSize="22dp"
app:itemIconTint="@color/drawer_item"
app:itemTextColor="@color/drawer_item"
app:labelVisibilityMode="labeled"
app:layout_constraintBottom_toTopOf="@id/Notification"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:menu="@menu/bottom_navigation_menu">

</com.google.android.material.bottomnavigation.BottomNavigationView>

<LinearLayout
android:id="@+id/Notification"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@color/notification_offline"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical"
android:weightSum="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">

<TextView
android:id="@+id/notificationText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@font/roboto"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="12sp"
android:textStyle="normal" />
</LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

<ProgressBar
android:id="@+id/progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_gravity="center|center_vertical"
android:indeterminate="false"
android:theme="@style/progressWhite"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

最佳答案

尝试保存 webview 的状态并仅在 savedstate 不为 null 时加载它

@Override
protected void onSaveInstanceState(Bundle outState )
{
super.onSaveInstanceState(outState);
web.saveState(outState);
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState)
{
super.onRestoreInstanceState(savedInstanceState);
web.restoreState(savedInstanceState);
}

关于java - 防止重新加载 WebView onResume(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60357272/

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