Android WebKit 简单例子

 根据Google上说。你可以在你的应用程序中调用Webkit工具,可以浏览一个www的页面,这一点都不假,下面来看看,3GEYENB ^"UOl4TlF}
原理我就不说了。大家可以看看APIs。3GEYE6QE b M l @
我给个简单的上网例子给大家体验下吧。我试验过,可以成功的。3GEYEU�L9gAi8^X,e9v
3GEYEMfd+,ZFO
package com.gggeye.android;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.webkit.DownloadListener;
import android.webkit.WebView;

public class WebViewDemo extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);
          webView1 = new WebView(this);
        webView1
                .loadData(
                        "<html><body>Can I focus?<br /><a href="#">No I cannot!</a>.</body></html>",
                        "text/html", "utf-8");
        this.setContentView(webView1);
        Logger.info("Download Faild _=> " + webView1.canGoBack());
        webView = new WebView(this);
        webView.loadUrl("http://www.3geye.net");
        //webView.setDownloadListener(new WebDownloadListener());
        
        new Thread(new WebDownloadListener(this)).start();
    }
    WebView webView1;
    class WebDownloadListener implements Runnable, DownloadListener {
        WebViewDemo wd;
        WebDownloadListener(WebViewDemo wd){
            this.wd = wd;
        }
        public void run() {
            int j=0;
            StringBuffer sb = new StringBuffer();
            sb.append("正在连接网络");
            while (true) {
                try {
                    Thread.sleep(4 * 1000);
                    j++;
                    sb.append(".");
                    webView1 = new WebView(wd);
                    webView1.loadData("<html><body><font color="red">"
                            + sb.toString() + " </font></html>", "text/html",
                            "utf-8");
                       Message msg = mHandler.obtainMessage();
                        mHandler.sendMessage(msg);
                     
                } catch (Throwable e) {
                    Logger.info(e.toString());
                     
                    e.printStackTrace();
                }
                if (j== 3) {
                    webView1 = null;
                       Message msg = mHandler.obtainMessage();
                        mHandler.sendMessage(msg);
                    break;
                }
            }
        }

        public void onDownloadFailed(String arg0, int arg1) {
            Logger.info("Download Faild _=> " + arg0);

        }

        public void onDownloadFinished(String arg0) {
            Logger.info("Download Finished => " + arg0);
            setContentView(webView);

        }

        public void onDownloadStart(String arg0, String arg1, long arg2,
                Message arg3, Message arg4) {
            Logger.info("Download Faild _=> " + arg0);

        }

        public void onDownloadSuspended(String arg0, Message arg1) {
            Logger.info("Download Faild _=> " + arg0);

        }

    }
   
       Handler mHandler = new Handler(){
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                //invalidate();
             if(webView1 == null)
                setContentView(webView);
             else
                 setContentView(webView1);
               
            }
       };

    WebView webView = null;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值