Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

80
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda