我正在使用Jetpack Compose创建一个简单的单词卡片。想法是当你点击卡片时,它会给出答案。然而,我遇到了一个基本问题。
不幸的是...我甚至找不到官方文档,所以我的学习方式就是信任自动纠正系统...
无论如何,我认为问题可能出在Box()或Text()上。我为盒子的Gravity添加了Align.CenterEnd。然而,在盒子居中方面,这似乎是唯一的方法。另一方面,Text()没有提供任何方法来实现这一点(它有gravity但似乎没有改变任何东西)
希望能得到正确的指导。
顺便说一句,我知道这会提供免费答案。但是我该如何在点击时更改$question的文本?因为我认为Composables会刷新?...因此,应该在屏幕上重新生成?也许不是吗?
谢谢!
val typography = MaterialTheme.typography
val context = ContextAmbient.current
var question = "How many Bananas should go in my Smoothie?"
Column(modifier = Modifier.padding(30.dp).then(Modifier.fillMaxWidth())
.then(Modifier.wrapContentSize(Alignment.Center))
.clickable(onClick = { Toast.makeText(context, "3 Bananas are needed!", Toast.LENGTH_LONG).show()} ) /*question = "3 Bananas required"*/
.clip(shape = RoundedCornerShape(16.dp))) {
Box(modifier = Modifier.preferredSize(350.dp)
.gravity(align = Alignment.CenterHorizontally)
.border(width = 4.dp, color = Gray, shape = RoundedCornerShape(16.dp)),
shape = RoundedCornerShape(2.dp),
backgroundColor = DarkGray,
gravity = Alignment.CenterEnd) {
Text("$question",
style = typography.h4,
)
}
}