1 、需求
- webview长按超链接获取链接文字及url
- webview长按图片链接类型获分别获取图片和链接的url
2、解决办法
1)、设置webview的OnLongClickListener事件,关键代码如下
companion object {const val LINK_TYPE = 1const val IMAGE_LINK_TYPE = 2}var mHandler = object : Handler() {override fun handleMessage(msg: Message) {super.handleMessage(msg)when (msg.what) {LINK_TYPE -> {var url = msg?.data?.get("url")//输出长按超链接的地址Log.d(TAG, "url is $url")var title = msg?.data?.get("title")//输出长按超链接的名字Log.d(TAG, "title is $title")}IMAGE_LINK_TYPE -> {//输出长按图片链接类型的url