美文网首页
取代WebView的库

取代WebView的库

作者: 王怀智 | 来源:发表于2017-05-27 10:43 被阅读236次

AgentWeb:

                     是一个高度封装的Android WebView库。具有简单易用,富有进度条,支持文件上传,下载,并且简化了javascript的通信等特点。

github地址 :

                      https://github.com/Justson/AgentWeb

AgentWeb跟WebView的区别:


库的使用:

引入: Gradle:compile 'com.just.agentweb:agentweb:1.0.3'

Activity用法:

mAgentWeb = AgentWeb.with(this)    //传入Activity

    .setAgentWebParent(mLinearLayout, new LinearLayout.LayoutParams(-1, -1))    //传入AgentWeb 的父控件 ,如果父控件为 RelativeLayout , 那么第二参数需要传入 RelativeLayout.LayoutParams

    .useDefaultIndicator()                      // 使用默认进度条

    .defaultProgressBarColor()             // 使用默认进度条颜色

    .setReceivedTitleCallback(mCallback)          //设置 Web 页面的 title 回调

    .createAgentWeb()//

    .ready()

    .go("http://www.jd.com");

Fragment用法:

@Override

public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {

    super.onViewCreated(view, savedInstanceState);

    mAgentWeb = AgentWeb.with(this.getActivity(), this)//这里需要把 Activity 、 和 Fragment  同时传入

    .setAgentWebParent((ViewGroup) view, new LinearLayout.LayoutParams(-1, -1))// 设置 AgentWeb 的父控件 , 这里的view 是 LinearLayout , 那么需要传入 LinearLayout.LayoutParams

    .useDefaultIndicator()// 使用默认进度条

    .setReceivedTitleCallback(mCallback) //标题回调

    .setSecurityType(AgentWeb.SecurityType.strict) //注意这里开启 strict 模式 , 设备低于 4.2 情况下回把注入的 Js 全部清空掉 , 这里推荐使用 onJsPrompt 通信

    .createAgentWeb()//

    .ready()//

    .go(getUrl());

}

相关文章

网友评论

      本文标题:取代WebView的库

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