-
-
Save bishoplee/947434fd6a1c758a2439e93fad90ee8e 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