android网页相关的知识

作者: 我是无穷 | 来源:发表于2017-05-09 00:31 被阅读37次

建议,先阅读官方指导文档https://developer.android.com/guide/webapps/webview.html

  1. 使用外部app打开网页;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(string));
  1. 本app内打开网页:
 webView.loadUrl(urlString);
 webView.setWebViewClient(new WebViewClient());
  1. WebviewClient和WebChromeClient的区别:
    webviewclient主要负责网络请求,常用的方法有:shouldOverloadUrl(), onPageStarted(), onPageFinished(), onReceivedError();
    webChromeClient主要负责和Js的交互,进度条,标题等:onJsAlert(), onJsConfirm(), onJsPrompt(), onProgressChanged(), onReceivedTitle(), onReceivedIcon();
  2. android和JavaScript的交互:
    android调用Js的方法:
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.loadUrl("javascript:callname(param)");

Js调用java方法:

class JsCallback {
    @JavascriptInterface()
    private void done(){
        //do something
    }
}
webView.addJavascriptInterface(new JsCallback(), "jsCallback");
  1. 做项目的经验:
    我们用企鹅的webview,使用之前必须有X5内核,微信、qq都已经有了,可以共享。内置的会随手机厂商不同而不同,麻烦;x5在不同手机都一样,而且功能强大;

相关文章

网友评论

    本文标题:android网页相关的知识

    本文链接:https://www.haomeiwen.com/subject/ogoutxtx.html