The desired behavior when opening an app is:
Mainactivity.java
myWebView.addJavascriptInterface(new JavaScriptInterface(this, cookieManager),"Android");
JavaScriptInterface.java
@JavascriptInterface
public void hideOrRemoveSplashScreen() {
objetcSplashScreen.doRemoveSplashScreen();
//...
}
HTML page (only for pages loaded with app, should detect with User Agent)
$(function() {
try{Android.hideOrRemoveSplashScreen()}catch(e){};
});
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/pullfresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<WebView
android:id="@+id/msw_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"></WebView>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
I don't know how to load in parallel a simple .png as splash screen with the rest of the app, and then, how to remove.
Seems this is working, not sure is the right way:
<?xml version="1.0" encoding="utf-8"?>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/pullfresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/splashimg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/darkblue"
android:src="@drawable/splash" />
<WebView
android:id="@+id/msw_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"></WebView>
</LinearLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
Then add objects in MainActivity.java
container = findViewById(R.id.container);
splash = findViewById(R.id.splashimg);
And finaly remove image onload inside Oncreate
myWebView.setWebChromeClient(new MyChrome() {
[...]
@Override
public void onProgressChanged(WebView view, int newProgress) {
if (newProgress == 100){
container.removeView(splash);
}
super.onProgressChanged(view, newProgress);
}
}
On load first page fires the removeView and some white body flashes until page is fully loaded, but can be fixed setting <body style='background-color'>