WebView 使用
?
package com.exmaple.app;import android.app.Activity;import android.os.Bundle;public class LoadWeb extends Activity {private WebView brower ;private Handler handler = new Handler(){@Overridepublic void handleMessage(Message msg) { /** * @param progress The progress for the progress bar. Valid ranges are from * 0 to 10000 (both inclusive). If 10000 is given, the progress * bar will be completely filled and will fade out. 一直以为是0 到100 **/ setProgress((Integer)msg.obj * 100);} };private WebChromeClient client = new WebChromeClient(){ @Overridepublic void onProgressChanged(WebView view, final int newProgress) { new Thread(){ public void run(){ Message msg =new Message() ;msg.obj = newProgress ;handler.sendMessage(msg);} } .start() ; }};private WebViewClient webClient = new WebViewClient(){@Override public boolean shouldOverrideUrlLoading(WebView view, String url) { //重写此方法表明点击网页里面的链接还是在当前的webview里跳转,不跳到浏览器那边 view.loadUrl(url); return true; }};@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);getWindow().requestFeature(Window.FEATURE_PROGRESS);setContentView(R.layout.web);setTitle("打开webView");setProgressBarVisibility(true);brower = (WebView) findViewById(R.id.brower); brower.loadUrl("http://163.com");brower.setWebChromeClient(client);brower.setWebViewClient(webClient);}}?
?