Skip to content

Instantly share code, notes, and snippets.

@JetXing
Created April 14, 2015 03:48
Show Gist options
  • Save JetXing/5860075320d933bd5b68 to your computer and use it in GitHub Desktop.
Save JetXing/5860075320d933bd5b68 to your computer and use it in GitHub Desktop.
add ProgressBar for WebView
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