While using “hitTestResult” on WebView, i actually face an issue while fetching the inner link of an “image link”, in which it seems to be worked with “SRC_IMAGE_ANCHOR_TYPE” but the result of this attempt results into fetching the image link instead of the inner website link, the program im building is a menu that pops up when long pressed over any type of link and the issue itself is about only “image links” AKA when you use SRC_IMAGE_ANCHOR_TYPE… How to solve this? thanks
val hitTestResult = (v as WebView).hitTestResult
when (hitTestResult.type) {
WebView.HitTestResult.SRC_ANCHOR_TYPE -> {
hitTestResult.extra?.let { showLinkMenu(it) }
true
}
WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE -> {
hitTestResult.extra?.let { showLinkMenu(it) }
true
}
WebView.HitTestResult.IMAGE_TYPE -> {
hitTestResult.extra?.let { showLinkMenu(it) }
true
}
else -> false
}
}
private fun showLinkMenu(url: String) {
val menuView = layoutInflater.inflate(R.layout.menu_link_options, null)
val popupWindow = PopupWindow(
menuView,
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
true
)
popupWindow.setBackgroundDrawable(ContextCompat.getDrawable(this, R.drawable.menu_background))
val linkUrlText = menuView.findViewById<TextView>(R.id.linkUrlText)
linkUrlText.text = url
menuView.findViewById<TextView>(R.id.openInNewTab).setOnClickListener {
addNewTab(url) // Open the link in a new tab
popupWindow.dismiss()
}
popupWindow.showAtLocation(webView, Gravity.CENTER, 0, 0)
}