zoukankan      html  css  js  c++  java
  • Android网络技术之WebView常用方法

    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);
        }
    }
    1
    2
    3
    4
    5
    <!--?xml version=1.0 encoding=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>

    结伴旅游,一个免费的交友网站:www.jieberu.com

    推推族,免费得门票,游景区:www.tuituizu.com

  • 相关阅读:
    mysql 自定义排序
    arcgis 好人
    eclipse启动tomcat,提示三个端口均被占用
    oracle 查看表空间创建日期
    navacat 链接oracle oci invalid handle
    java +mysql 递归排序/* START WITH aa.parentid IN ( 10000, 20000, 30000, 40000, 50000, 60000, 70000 ) connect BY prior aa.id = aa.parentid ORDER siblings BY aa.id ASC*/ to
    Double 转 BigDecimal
    mysql 死锁 Waiting for stored function metadata lock
    Graphtree--zabbix增强功能(一屏展示所有内容)
    zabbix 分布式监控(proxy)源码安装
  • 原文地址:https://www.cnblogs.com/rabbit-bunny/p/4226953.html
Copyright © 2011-2022 走看看