WebView Common methods of Android network technology

Source: Internet
Author: User

public class WebViewTest extends Activity {    private WebView wv;    private EditText et;        @Override    protected void onCreate(Bundle savedInstanceState) {        // TODO Auto-generated method stub        super.onCreate(savedInstanceState);        setContentView(R.layout.webview);        wv = (WebView) findViewById(R.id.webview_wv);        wv.loadUrl(http://www.baidu.com);        initWV();        et = (EditText) findViewById(R.id.webview_et);        et.setSelection(et.getText().length());    }    private void initWV() {        // TODO Auto-generated method stub        //设置内核,支持ajax        wv.setWebChromeClient(new WebChromeClient());        //new WebViewClient()默认基于webkit内核        wv.setWebViewClient(new WebViewClient(){            //从一个网页跳到另一个网页的方式,return true则为目标页面在当前webView打开,不会调用系统默认浏览器            @Override            public boolean shouldOverrideUrlLoading(WebView view, String url) {                // TODO Auto-generated method stub                return true;            }            //当页面加载完毕调用的方法            @Override            public void onPageFinished(WebView view, String url) {                // TODO Auto-generated method stub                Toast.makeText(WebViewTest.this, 加载完毕!, 0).show();                super.onPageFinished(view, url);            }                        //页面开始加载时调用的方法            @Override            public void onPageStarted(WebView view, String url, Bitmap favicon) {                // TODO Auto-generated method stub                et.setText(url);                super.onPageStarted(view, url, favicon);            }        });                //设置支持js脚本        wv.getSettings().setJavaScriptEnabled(true);        //设置支持手指放大        wv.getSettings().setSupportZoom(true);        wv.getSettings().setBuiltInZoomControls(true);    }        public void load(View view){        //加载URL        wv.loadUrl(et.getText().toString().trim());    }        public void reload(View view){        //重新载入,刷新页面        wv.reload();    }        public void back(View view){        //后退        wv.goBack();    }        //设置(拦截)手机上的按键触摸时间    @Override    public boolean onKeyDown(int keyCode, KeyEvent event) {        // TODO Auto-generated method stub        switch (keyCode) {        case KeyEvent.KEYCODE_BACK:            wv.goBack();            break;         default:            break;        }        return super.onKeyDown(keyCode, event);    }}

?
12345 <!--?xml version=1.0encoding=utf-8?--><linearlayout android:layout_height="match_parent" android:layout_width="match_parent" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android"></linearlayout>

A companion tour, a free dating site: www.jieberu.com

Push family, free tickets, scenic spots: www.tuituizu.com

WebView Common methods of Android network technology

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.