加载webview出现的问题(华为mate9)

1.出现空白页的解决方法

  1. webView.setWebViewClient(new WebViewClient(){     
  2.                 public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error){     
  3.                           //handler.cancel(); 默认的处理方式,WebView变成空白页     
  4. //                        //接受证书     
  5.                     handler.proceed();  
  6.                          //handleMessage(Message msg); 其他处理     
  7.                }  
  8.          }); 
2.华为mate9中打开https的webview页面是空白页面。
解决方案:更新 android system webview即可。
3.webview和js的交互
// JavaScript调用Android函数:
// 先建立桥梁类,将要调用的Android代码写入桥梁类的public函数
// 绑定桥梁类和WebView中运行的JavaScript代码
// 将一个对象起一个别名传入,在JS代码中用这个别名00这个对象,可以调用这个对象的一些方法
webview.addJavascriptInterface(new WebAppInterface(this),
        "root");

/**
 * 自定义的Android代码和JavaScript代码之间的桥梁类
 *
 * @author 1
 */
public class WebAppInterface {
    Context mContext;

    /**
     * Instantiate the interface and set the context
     */
    WebAppInterface(Context c) {
        mContext = c;
    }

    /**
     * Show a toast from the web page
     */
    // 如果target 大于等于API 17,则需要加上如下注解
    @JavascriptInterface
    public void hybridProtocol(String flag) {
//接受js返回的结果
}}
4.将webview的标题设置成本页面的标题

@Override
public void onPageFinished(WebView view, String url) {
    “标题控件”.setText(view.getTitle());
}

你可能感兴趣的:(加载webview出现的问题(华为mate9))