捕获/传递 webview 对表面可组合的点击
我希望我的网络视图不响应任何触摸;我只是希望它显示内容(因此 touchListener
返回 true)。父 Surface
可组合项应处理触摸。但这不起作用。
@OptIn(ExperimentalMaterialApi::class)
@Preview
@Composable
fun MyComposable() {
Surface(
modifier = Modifier.size(250.dp).padding(10.dp),
onClick = { Log.e("TEST", "Clicked") },
elevation = 5.dp
) {
AndroidView(
factory = { context ->
WebView(context).apply {
this.setOnTouchListener { _, _ -> true }
}
},
update = {
it.loadUrl("https://stackoverflow.com/")
}
)
}
}
I want my webview to not respond to any touches; I just want it to display content(hence the touchListener
returning true). The parent Surface
composable should handle the touches. But it doesn't work.
@OptIn(ExperimentalMaterialApi::class)
@Preview
@Composable
fun MyComposable() {
Surface(
modifier = Modifier.size(250.dp).padding(10.dp),
onClick = { Log.e("TEST", "Clicked") },
elevation = 5.dp
) {
AndroidView(
factory = { context ->
WebView(context).apply {
this.setOnTouchListener { _, _ -> true }
}
},
update = {
it.loadUrl("https://stackoverflow.com/")
}
)
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
目前唯一有效的解决方案是在
WebView
顶部放置一个空的Surface
可组合项来捕获点击。但这个解决方案似乎有点老套。 欢迎更好的解决方案。
Currently the only solution that works is having an empty
Surface
composable on top of theWebView
to capture the clicks.But this solution seems a bit hacky. Better solutions are welcome.