AgentWeb 是一个基于的 Android WebView ,极度容易使用以及功能强大的库,提供了 Android WebView 一系列的问题解决方案 ,并且轻量和极度灵活。
使用- 引用依赖
implementation 'com.github.Justson.AgentWeb:agentweb-core:v5.0.0-alpha.1-androidx' // (必选) implementation 'com.github.Justson.AgentWeb:agentweb-filechooser:v5.0.0-alpha.1-androidx' // (可选) implementation 'com.github.Justson:Downloader:v5.0.0-androidx' // (可选)
- 布局文件
- 初始化
val mAgentWeb = AgentWeb.with(this)
.setAgentWebParent(binding.container, -1, LinearLayoutCompat.LayoutParams(-1, -1))
.useDefaultIndicator()
.setWebChromeClient(mChromeChromeClient)
.setWebViewClient(mWebViewClient)
.setOpenOtherPageWays(DefaultWebClient.OpenOtherPageWays.ASK)
.createAgentWeb()
.ready()
.get()
mAgentWeb.urlLoader.loadUrl(URL)
或者直接访问网页
val mAgentWeb = AgentWeb.with(this)
.setAgentWebParent(binding.container, -1, LinearLayoutCompat.LayoutParams(-1, -1))
.useDefaultIndicator()
.setWebChromeClient(mChromeChromeClient)
.setWebViewClient(mWebViewClient)
.setOpenOtherPageWays(DefaultWebClient.OpenOtherPageWays.ASK)
.createAgentWeb()
.go(HOME_URL)
- webChromeClinet设置
private val mChromeChromeClient = object : WebChromeClient() {
override fun onReceivedTitle(view: WebView?, title: String?) {
binding.tvTitle.text = title
}
}
- Javascript 通信
//Javascript 方法
function callByAndroid(){
console.log("callByAndroid")
}
Android 端
mAgentWeb.getJsEntraceAccess().quickCallJs("callByAndroid");



