@Composable
fun ButtonTest() {
val context = LocalContext.current
Column {
Button(
modifier = Modifier
.fillMaxWidth()
.padding(5.dp),
onClick = {
Toast.makeText(context, "点击了按钮", Toast.LENGTH_SHORT).show()
},
//设置边框宽度和颜色
border = BorderStroke(2.dp, Color.Yellow),
//设置圆角
shape = RoundedCornerShape(8.dp),
colors = ButtonDefaults.buttonColors(
//内容颜色
contentColor = Color.Green,
),
) {
Text(text = "按钮")
}
}
}
onClick属性:设置点击事件监听。
BorderStroke设置边框宽度和颜色。
RoundedCornerShape设置按钮圆角。
contentColor设置按钮字体颜色。