美文网首页
webView的封装

webView的封装

作者: buhuiming | 来源:发表于2018-06-15 11:43 被阅读0次

BHMAndroid工程:一些常用的工具类,以及常用的控件,主要用来提高开发效率。(GitHub


集成:

    compile 'com.bhm.sdk.bhmlibrary:BHMLibrary:version' (version不定时更新)
    <dependency>
      <groupId>com.bhm.sdk.bhmlibrary</groupId>
      <artifactId>BHMLibrary</artifactId>
      <version>version</version>
      <type>pom</type>
    </dependency>

目前库包含了一些项目中常用的模块,后续会慢慢的添加完善。

3.png 4.png

使用步骤

1、xml布局中添加

<com.bhm.sdk.bhmlibrary.views.BaseWebView
    android:id="@+id/webView"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

2、设置

webView = (BaseWebView) findViewById(R.id.webView);
    //webView.getSettings().setJavaScriptEnabled(true);
   //webView.setErrorPagePath("file:///android_asset/t_error.html");
    webView.setProgressBarDrawable(R.drawable.progressbar);
    webView.init(this, "https://www.baidu.com", true, new WebViewCallBack() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return false;
        }

        //可以重写其他方法:onPageStarted、onPageFinished、onLoadResource、onReceivedError、onReceivedTitle
    });

3、方法介绍

  • (1)通过webView.getSettings()获取setting,对webView的属性重新进行设置。
  • (2)添加进度条webView.setProgressBarDrawable(R.drawable.progressbar);默认为蓝色的。若需要隐藏,则init方法第三个参数传递false即可。
  • (3)webView.setErrorPagePath加载失败显示的页面,默认请参考图片显示,可自定义。
  • (4)解决了跨域请求问题,Https SSL认证不通过问题,部分机型显示空白页问题,重定向问题等。

相关文章

网友评论

      本文标题:webView的封装

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