Bonjour tout le monde !

Je dois préciser avant de commencer que je viens de commencer sur Android Studio et que je suis débutant en Java !

Je n'ai pas pu résoudre ce problème depuis un moment maintenant.

Bien avant d'ajouter un écran de démarrage,(Splash Screen) à mon application, lors du lancement, j'avais un écran blanc qui apparaissait (2 à 3 secondes) avant ma WebView.

L'ajout d'un Splash screen n'a en aucun cas résolu le problème.
En effet :

1. Le Splash Screen se lance
2. Ecran Blanc d'une durée de 3 secondes environ
3. Ma Webview se lance.

J'ai essayé différentes méthodes que j'ai pu voir sur les forums, dont celle-ci:
Ajouter ce Style dans :

Styles.xml

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
<style name="Theme.NoPreviewWindow" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowIsTranslucent">true</item>
</style>
Et l'appliquer dans :

AndroidManifest.xml

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
<activity android:name="com.truck.brosburger.MainActivity"
android:theme="@style/Theme.NoPreviewWindow">
Mais cela ne fonctionne pas chez moi !

J'ajoute tout mon code en dessous :


MainActivity.java


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
package com.truck.brosburger;
 
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


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?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

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?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>
En vous remerciant pour vos futures réponses !