安卓webview
import android.app.Activity; import android.os.Bundle; import android.view.KeyEvent; import android.view.View; import android.view.Window; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.ProgressBar; public class chengji extends Activity { private WebView wv; private ProgressBar progressBar; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.webview); progressBar = (ProgressBar) findViewById(R.id.pro); wv = (WebView) findViewById(R.id.webview); wv.getSettings().setAllowFileAccess(true); wv.getSettings().setJavaScriptEnabled(true); wv.loadUrl("http://www.gdousu.com/wap/tools/grade.aspx"); wv.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); if (wv.getContentHeight() != 0) { } } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }); wv.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { super.onProgressChanged(view, newProgress); if (newProgress == 0) { progressBar.setVisibility(View.VISIBLE); } progressBar.setProgress(newProgress); progressBar.postInvalidate(); if (newProgress == 100) { progressBar.setVisibility(View.GONE); } } }); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && wv.canGoBack()) { wv.goBack(); return true; } else return super.onKeyDown(keyCode, event); } }
当前文章:安卓webview
当前地址:http://lswzjz.com/article/ipcjoc.html