Created
April 14, 2015 03:48
-
-
Save JetXing/5860075320d933bd5b68 to your computer and use it in GitHub Desktop.
add ProgressBar for WebView
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
this.getWindow().requestFeature(Window.FEATURE_PROGRESS); | |
setContentView(R.layout.main ); | |
final Activity MyActivity = this; | |
// Makes Progress bar Visible | |
getWindow().setFeatureInt( Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON); | |
webview = (WebView) findViewById(R.id.webview); | |
webview.setWebChromeClient(new WebChromeClient() { | |
public void onProgressChanged(WebView view, int progress) | |
{ | |
//Make the bar disappear after URL is loaded, and changes string to Loading... | |
MyActivity.setTitle("Loading..."); | |
MyActivity.setProgress(progress * 100); //Make the bar disappear after URL is loaded | |
// Return the app name after finish loading | |
if(progress == 100) | |
MyActivity.setTitle(R.string.app_name); | |
} | |
}); | |
webview.setWebViewClient(new HelloWebViewClient()); | |
webview.getSettings().setJavaScriptEnabled(true); | |
webview.loadUrl("https://gitcafe.com"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment