如何在Jetpack Compose中获取上下文

Tayyab MuGhal先生
fun createListItem(itemIndex: Int) {
Padding(left = 8.dp, right = 8.dp, top = 8.dp, bottom = 8.dp) {
    FlexRow(crossAxisAlignment = CrossAxisAlignment.Center) {
        expanded(1.0f) {
            Text("Item $itemIndex")
        }
        inflexible {
            Button(
                "Button $itemIndex",
                style = ContainedButtonStyle(),
                onClick = {
                    Toast.makeText(
                        this@MainActivity,
                        "Item name $itemIndex",
                        Toast.LENGTH_SHORT
                    ).show()
                })

        }
    }
  }
}

我尝试以正常方式制作吐司。但是我遇到了错误,我尝试了很多倍数源,但是失败了。

拉卡·阿迪·努格罗霍(Raka Adi Nugroho)

您可以使用define访问上下文ambientContext

例:

val context = ContextAmbient.current

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章