我的进度对话框只有在第一次打开才有显示
都按照老师的来,怎么就是不行
都按照老师的来,怎么就是不行
2016-08-06
package com.example.webview; import org.apache.http.client.entity.UrlEncodedFormEntity; import android.app.Activity; import android.app.ProgressDialog; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; import android.webkit.WebChromeClient; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.Toast; public class MainActivity extends Activity { private String url = "http://www.baibu.com/"; private WebView webView; private ProgressDialog Dialog; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Uri uri = Uri.parse(url); // Intent intent = new Intent(Intent.ACTION_VIEW,uri); // startActivity(intent); init(); } private void init() { // TODO Auto-generated method stub webView = (WebView) findViewById(R.id.webView); webView.loadUrl(url); webView.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }); WebSettings Settings = webView.getSettings(); Settings.setJavaScriptEnabled(true); Settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); webView.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { // TODO Auto-generated method stub if (newProgress == 100) { closeDialog(); } else { openDialog(newProgress); } super.onProgressChanged(view, newProgress); } private void closeDialog() { // TODO Auto-generated method stub if (Dialog != null && Dialog.isShowing()) { Dialog.dismiss(); Dialog = null; } } private void openDialog(int newProgress) { // TODO Auto-generated method stub if (Dialog == null) { Dialog = new ProgressDialog(MainActivity.this); Dialog.setTitle("正在加载"); Dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); Dialog.setProgress(newProgress); Dialog.show(); } else { Dialog.setProgress(newProgress); } } }); } // 改写物理一次返回的按键的逻辑 @Override public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub if (keyCode == KeyEvent.KEYCODE_BACK) { if (webView.canGoBack()) { Toast.makeText(this, webView.getUrl(), Toast.LENGTH_SHORT) .show(); webView.goBack(); return true; } else { System.exit(0); } } return super.onKeyDown(keyCode, event); } }
这是我的,你看一下,是不是放错位置了?或者其他的
举报