I have a MainActivity that installSplashScreen()
at first, then it will load the WebView
, the webviewFragment is in other file, I am trying to use splashScreen.setKeepOnScreenCondition{ }
to keep splash screen showing until the webviewFragment reach to onPageFinished()
state, how am I supposed to do that?
CodePudding user response:
There are several alternatives to communicate both components:
- you may use a listener in your fragment that notifies the activity,
- you may cast the activity from fragment context to notify it,
- you may use the activity ViewModel and observer pattern to notify the change
- singletons though not recommended
- event bus implementations
- send a broadcast and receive it with a BroadCastListener in your splash or MainActivity.
CodePudding user response:
You can use a layout like this
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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">
<WebView
android:id="@ id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@ id/cl_container_splash"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>
- Frame Layout (Parent)
- WebView (visibility = gone)
- Splash Screen (visible)
Now load your url, and in your onPageFinished()
call following.
binding.webView.visibility = View.Visible
binding.root.removeView(binding.clContainerSplash)