[英]Why does my Application crash at startup?
我無法將Webview應用程序中的進度欄更改為circle。該應用程序在啟動時崩潰..這是代碼
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webview = (WebView) findViewById(R.id.webview);
WebSettings websettings = webview.getSettings();
websettings.setJavaScriptEnabled(true);
getWindow().requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS); // Request progress circle
setProgressBarIndeterminateVisibility(true); // Show progress circle
// webview.setWebViewClient(new WebViewClient());
final Activity activity = this;
webview.setWebChromeClient(new WebChromeClient(){
public void onProgressChanged(WebView view, int progress) {
activity.setTitle("Loading...");
activity.setProgress(progress * 100);
if(progress == 100)
setProgressBarIndeterminateVisibility(false); // Hide progress circle when page loaded
activity.setTitle("Title");
}
});
if (savedInstanceState == null)
{
webview.loadUrl("http://www.proboards.com/");
}
}
有人可以幫忙嗎?
我發現您的代碼中存在一些缺陷。
As far as I know, the ProgressBar value should be less than or equal to 100.
You are setting it to (progress * 100)
Also, once progress == 100, you hide the progress bar,
this will take place when progress = 1. Then you hide the progress bar.
private ProgressBar mProgress;
private int mProgressStatus = 0;
mProgress = (ProgressBar) findViewById(R.id.progress_bar);
// Start lengthy operation in a background thread
new Thread(new Runnable() {
public void run() {
while (mProgressStatus < 100) {
mProgressStatus = doWork();
// Update the progress bar
mHandler.post(new Runnable() {
public void run() {
mProgress.setProgress(mProgressStatus);
}
});
}
}
}).start();
您的應用程序崩潰,因為此行:
Activity.getWindow().requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
需要在調用 Activity.setContentView(...);
之前調用 Activity.setContentView(...);
您之前調用過setContentView(...),這就是您的應用程序崩潰的原因。
這是從Android-Developer頁面上的原因:
http://developer.android.com/reference/android/view/Window.html#requestFeature%28int%29
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.