You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GlanceAppWidget可点击行问题:内部元素抢占焦点与点击事件

解决Glance Widget中Row点击区域不包含Image和Text的问题

在Glance库中,Image和Text组件默认会消费点击事件,导致父容器Row的点击逻辑只有在点击组件外的空白区域时才会触发,点击组件本身无响应。

解决方法是给Image和Text添加GlanceModifier.clickable(null),让它们不拦截点击事件,将事件透传给父级的Row:

Row(
    verticalAlignment = Alignment.CenterVertically,
    modifier = GlanceModifier.fillMaxWidth().clickable(
        actionStartActivity(
            createOpenActivityIntent(
                context = LocalContext.current
            )
        )
    )
) {
    Image(
        modifier = GlanceModifier.padding(end = 8.dp).clickable(null),
        provider = ImageProvider(R.drawable.ic_open),
        contentDescription = null
    )
    Text(
        text = LocalContext.current.getString(R.string.open),
        modifier = GlanceModifier.clickable(null)
    )
}

这样修改后,整个Row的所有区域(包括Image和Text部分)都会响应点击事件,触发跳转逻辑。

内容的提问来源于stack exchange,提问作者E I

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 21:35:21