Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

75
Views
Splash screen on a Android WebView while loads first time until javascript onload fires

The desired behavior when opening an app is:

  • Show splash screen and load URL in parallel
  • When a javascript interface fired when onload just remove the splash screen

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.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Seems this is working, not sure is the right way:

  1. Modify activity_main.xml in order to put a container with the image and webview
    <?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'>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!