I’ve pretty much followed all the necessary steps for adding a ProgressBar to my WebView using ActionBarSherlock, but I don’t get any results on pre-Android 4.0. Can anyone help? I’ve imported Window from ABS, added requestWindowFeature(Window.FEATURE_PROGRESS); before setting content, i just don’t know what to do. Please don’t tell me to follow the samples, since I’ve tried that and I’ve gotten no results. Thank you.
Here is the code for MainActivity.class
package com.twk95.webviewtest;
import android.content.Intent;
import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.view.Window;
public class MainActivity extends SherlockActivity {
public static WebView webView;
final SherlockActivity MyActivity = this;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.activity_main);
webView = (WebView) findViewById(R.id.WebView);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView webview, String url) {
webview.loadUrl(url);
return true;
}
});
webView.loadUrl("http://www.google.com");
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
MyActivity.setTitle("Loading...");
MyActivity.setProgress(progress * 100);
setSupportProgressBarVisibility(true);
if (progress == 100) {
MyActivity.setTitle(R.string.app_name);
setSupportProgressBarVisibility(false);
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getSupportMenuInflater().inflate(R.menu.webview_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.webReload:
webView.reload();
break;
case android.R.id.home:
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
return true;
}
return false;
}
}
Make sure that the
requestWindowFeaturemethod is usingcom.actionbarsherlock.app.SherlockActivity.requestWindowFeature(long featureId)then usesetSupportProgress(int progress)to update it rather than usingMyActivity.setProgress()