锁定屏幕后,按下关闭按钮解锁后,我的网页视图会重新加载。
我发现问题出在
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>