Last active
March 12, 2023 03:18
-
-
Save stevesohcot/57b210013d413dd553407431cb394cec to your computer and use it in GitHub Desktop.
Android Studio WebView - splash screen (complete)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.diamondium.samplewebview; | |
| import android.support.v7.app.AppCompatActivity; | |
| import android.os.Bundle; | |
| import android.webkit.WebView; | |
| import android.webkit.WebViewClient; | |
| import android.graphics.Bitmap; | |
| import android.view.View; | |
| import android.widget.ProgressBar; | |
| public class MainActivity extends AppCompatActivity { | |
| String ShowOrHideWebViewInitialUse = "show"; | |
| private WebView webview ; | |
| private ProgressBar spinner; | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_main); | |
| webview =(WebView)findViewById(R.id.webView); | |
| spinner = (ProgressBar)findViewById(R.id.progressBar1); | |
| webview.setWebViewClient(new CustomWebViewClient()); | |
| webview.getSettings().setJavaScriptEnabled(true); | |
| webview.getSettings().setDomStorageEnabled(true); | |
| webview.setOverScrollMode(WebView.OVER_SCROLL_NEVER); | |
| webview.loadUrl("https://www.google.com"); | |
| } | |
| // This allows for a splash screen | |
| // (and hide elements once the page loads) | |
| private class CustomWebViewClient extends WebViewClient { | |
| @Override | |
| public void onPageStarted(WebView webview, String url, Bitmap favicon) { | |
| // only make it invisible the FIRST time the app is run | |
| if (ShowOrHideWebViewInitialUse.equals("show")) { | |
| webview.setVisibility(webview.INVISIBLE); | |
| } | |
| } | |
| @Override | |
| public void onPageFinished(WebView view, String url) { | |
| ShowOrHideWebViewInitialUse = "hide"; | |
| spinner.setVisibility(View.GONE); | |
| view.setVisibility(webview.VISIBLE); | |
| super.onPageFinished(view, url); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment