• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps How remove white screen before Webview?

Hello :)
I should clarify before starting that I have just started on Android Studio and that I am a beginner in Java ! :)

I haven't been able to fix this problem for a while now.

Long before I add a splash screen, when I launched my application I had a white screen that appeared (2 to 3 seconds) before my webview.

Adding a Screen splash did not solve the problem. Indeed the Splash screen is launched, white screen and only after the webview.

I tried different method that I could see on the forums including this one:

Add this style to

Styles.xml
HTML:
<style name="Theme.NoPreviewWindow" parent="Theme.AppCompat.NoActionBar">
        <item name="android:windowIsTranslucent">true</item>
    </style>

And Apply to :

AndroidManifest.xml

HTML:
<activity android:name="com.truck.brosburger.MainActivity"
             android:theme="@style/Theme.NoPreviewWindow">

BUt doesn't work for me. what should I do ? Thank you in advance for your answers :) Below all my code :

MainActivity.java

Java:
import androidx.appcompat.app.AppCompatActivity;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;

import org.imaginativeworld.oopsnointernet.ConnectionCallback;
import org.imaginativeworld.oopsnointernet.NoInternetDialog;
import org.imaginativeworld.oopsnointernet.NoInternetSnackbar;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;



public class MainActivity extends AppCompatActivity {


    private AdView mAdView;
    private WebView webView;
    private SwipeRefreshLayout mySwipeRefreshLayout;


    // Dialog No internet connexion
    NoInternetDialog noInternetDialog;

    // Dialog No internet connexion Snackbar
    NoInternetSnackbar noInternetSnackbar;


    @Override
    protected void onCreate(Bundle savedInstanceState) {



        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);


        mySwipeRefreshLayout = (SwipeRefreshLayout)this.findViewById(R.id.swipeContainer);
        String url ="https://www.brosburger.fr/menu";

        webView =(WebView) findViewById(R.id.webView);

        webView.getSettings().setJavaScriptEnabled(true);
        webView.setWebViewClient(new WebViewClient());

        webView.loadUrl(url);
        mySwipeRefreshLayout.setOnRefreshListener(
                new SwipeRefreshLayout.OnRefreshListener() {
                    @Override
                    public void onRefresh() {
                        webView.reload();
                        mySwipeRefreshLayout.setRefreshing(false);
                    }
                }
        );



        //PuB Admob
        mAdView = findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);





        //chargement de la page
        final ProgressDialog progressBar = new ProgressDialog(MainActivity.this);
        progressBar.setMessage("Chargement de la Page...");




            webView.setWebViewClient(new WebViewClient() {


                public boolean shouldOverrideUrlLoading(WebView view, String url) {

                    view.loadUrl(url);
                    return true;

                }

                @Override
                public void onPageStarted(WebView view, String url, Bitmap favicon) {



                    super.onPageStarted(view, url, favicon);


                    if (!progressBar.isShowing()) {
                        progressBar.show();


                    }
                }

                public void onPageFinished(WebView view, String url) {



                         if (progressBar.isShowing()) {
                           progressBar.dismiss();


                    }
                }






            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                if (progressBar.isShowing()) {
                    progressBar.dismiss();
                    webView.loadUrl("about:blank");

                    AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                    builder.setTitle(R.string.app_name);
                    builder.setIcon(R.drawable.logo);
                    builder.setMessage("Aucune Connexion Internet Veuillez Redémarrer l'Application")
                            .setCancelable(false)
                            .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int id) {
                                    finish();
                                }
                            });

                    AlertDialog alert = builder.create();
                    alert.show();

                }
            }
        });
    }

    //Dialog No internet connexion
    @Override
    protected void onResume() {
        super.onResume();






        // No Internet Dialog
        NoInternetDialog.Builder builder1 = new NoInternetDialog.Builder(this);

        builder1.setConnectionCallback(new ConnectionCallback() { // Optional

            @Override
            public void hasActiveConnection(boolean hasActiveConnection) {
                // ...
            }
        });
        builder1.setCancelable(false); // Optional
        builder1.setNoInternetConnectionTitle("Aucune Connexion Internet"); // Optional
        builder1.setNoInternetConnectionMessage("Vérifiez votre connexion puis réessayez"); // Optional
        builder1.setShowInternetOnButtons(true); // Optional
        builder1.setPleaseTurnOnText("Activer"); // Optional
        builder1.setWifiOnButtonText("Wifi"); // Optional
        builder1.setMobileDataOnButtonText("Données mobiles"); // Optional

        builder1.setOnAirplaneModeTitle("Aucune Connexion Internet"); // Optional
        builder1.setOnAirplaneModeMessage("Vous avez activé le mode avion"); // Optional
        builder1.setPleaseTurnOffText("Veuillez le désactiver"); // Optional
        builder1.setAirplaneModeOffButtonText("Mode Avion"); // Optional
        builder1.setShowAirplaneModeOffButtons(true); // Optional


        noInternetDialog = builder1.build();


        // No Internet Snackbar
        NoInternetSnackbar.Builder builder2 = new NoInternetSnackbar.Builder(this, (ViewGroup) findViewById(android.R.id.content));

        builder2.setConnectionCallback(new ConnectionCallback() { // Optional
            @Override
            public void hasActiveConnection(boolean hasActiveConnection) {
                // ...
            }
        });
        builder2.setIndefinite(true); // Optional
        builder2.setNoInternetConnectionMessage("Aucune Connexion Internet"); // Optional
        builder2.setOnAirplaneModeMessage("Vous avez activé le mode avion!"); // Optional
        builder2.setSnackbarActionText("Paramètres");
        builder2.setShowActionToDismiss(false);
        builder2.setSnackbarDismissActionText("OK");

        noInternetSnackbar = builder2.build();

    }

    @Override
    protected void onPause() {
        super.onPause();

        // No Internet Dialog
        if (noInternetDialog != null) {
            noInternetDialog.destroy();
        }

        // No Internet Snackbar
        if (noInternetSnackbar != null) {
            noInternetSnackbar.destroy();
        }


    }

    @Override
    protected void onRestart() {
        super.onRestart();

            }




    @Override
    protected void onStop() {
        super.onStop();

            }




    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {

        final WebView simpleWebView = (WebView) findViewById(R.id.webView);

        if ((keyCode == KeyEvent.KEYCODE_BACK) && simpleWebView.canGoBack()) {
            //if Back key pressed and webview can navigate to previous page
            simpleWebView.goBack();
            // go back to previous page
            return true;
        }

        return super.onKeyDown(keyCode, event);
    }


}

AndroidManifest.xml

HTML:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.truck.brosburger">

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>



    <application
        android:allowBackup="true"
        android:icon="@mipmap/icone"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">



        <activity
            android:name="com.truck.brosburger.SplashScreenActivity">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>


        <activity android:name="com.truck.brosburger.MainActivity"
                  android:theme="@style/Theme.NoPreviewWindow">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

            </intent-filter>
        </activity>

        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-8922758574590712~6416122275"/>


    </application>

Activity_Main.xml

HTML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">



    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
        android:id="@+id/swipeContainer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">


        <WebView
        android:id="@+id/webView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:layout_editor_absoluteX="48dp"
        tools:layout_editor_absoluteY="40dp">

    </WebView>


    </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

    <com.google.android.gms.ads.AdView
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        ads:adSize="BANNER"
        app:adUnitId="@string/banner_ad_unit_id" />




</RelativeLayout>
Thanks ! :)
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones