WebLoading开源库,支持https访问

关于

  因为最近公司项目用到的webview比较多,一方面涉及到了用户体验感(加载进度条可DIY),另一方面,去div样式、加载https网址适配、解决重定向问题、多页面加载问题。所以就有了webLoading1.0.0版本,后续还会有一些丰富的接口方法待完善。开源库地址

引用

  第一步,在工程的build下添加如下:

allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}

  第二步,在项目的build下添加如下:

implementation 'com.github.Tobeyr1:webLoading:1.0.1'

使用

第一步,添加控件

  在布局文件中添加如下:

<com.tobery.weblib.WebViewLoading
        android:id="@+id/web"
        android:layout_height="match_parent"
        android:layout_width="match_parent" />

第二步,在活动页面实例化,并使用

WebViewLoading webViewLoading =(WebViewLoading) findViewById(R.id.web);
//webview的基本配置(包括js开启、h5支持、https支持、加载进度条)
webViewLoading.setSettings(this);
//加载的url
webViewLoading.setUrl("https://blog.csdn.net/Tobey_r1");
//页面暂停
webViewLoading.setPause();
//页面恢复
webViewLoading.setResume();
//页面销毁
webViewLoading.setDestory();

  当然了,别忘记在配置文件上添加INTERENT权限。

效果图

在这里插入图片描述
  可以看到是有一个黑色的进度条。简单的使用到这就完成了。

进阶使用

去除类似广告头部或其他元素

 //移除网页元素
 webViewLoading.removeDiv("csdn-toolbar");

  移除效果如下:
移除前:
在这里插入图片描述
移除后:
在这里插入图片描述

实现页面回退

//实现页面回退
 webViewLoading.goback(MainActivity.this);

效果如下:
在这里插入图片描述

可DIY进度条加载样式

  如果你只想修改成你喜欢的样式,且每个使用webloading的地方样式一致,只需要在你的项目中的drawable中添加如下pg.xml:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item android:id="@android:id/background">
        <shape>
            <corners android:radius="2dp" />
            <!--背景颜色-->
            <gradient
                android:angle="270"
                android:centerColor="#dcdcdc"
                android:endColor="#dcdcdc"
                android:startColor="#dcdcdc" />
        </shape>
    </item>
    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <corners android:radius="2dp" />
                <!--进度条颜色-->
                <gradient
                    android:centerColor="#FF0000"
                    android:endColor="#B2000000"
                    android:startColor="#02A549" />

            </shape>
        </clip>
    </item>

</layer-list>

修改后,运行效果如下:
在这里插入图片描述

//调用样式
webViewLoading.setProgressColor(getResources().getDrawable(R.drawable.pg1));

新增获取网页标题

  JAVA获取标题方法:

 webViewLoading.getTitle(title ->{
            Log.e("标题",title);
            return null;
        });

  Kotlin获取标题方法:

 webViewLoading.getTitle {
            //获取标题
        }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

雪の星空朝酱

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值