Last active
March 2, 2019 16:27
-
-
Save stevesohcot/520b1f1983b3eb781bd3c80bae0d6fb9 to your computer and use it in GitHub Desktop.
Android WebView - Splash/Loading screen (incomplete)
This file contains 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 { | |
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) { | |
webview.setVisibility(webview.INVISIBLE); | |
} | |
@Override | |
public void onPageFinished(WebView view, String url) { | |
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