Button
Button¶
属性¶
@Composable
fun Button(
onClick: () -> Unit,
modifier: Modifier = Modifier,
enabled: Boolean = true,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
elevation: ButtonElevation? = ButtonDefaults.elevation(),
shape: Shape = MaterialTheme.shapes.small,
border: BorderStroke? = null,
colors: ButtonColors = ButtonDefaults.buttonColors(),
contentPadding: PaddingValues = ButtonDefaults.ContentPadding,
content: @Composable RowScope.() -> Unit
): Unit
基本用法¶
@Composable
fun ButtonSample() {
Button(
onClick = {
Log.d("ButtonSample", "click the button")
},
) {
Text(text = "这里有一个按钮")
}
}
参数¶
enabled
是否启用或禁用
elevation
投影border
边框线
colors
设置颜色,可以设置背景颜色、前景颜色、禁用状态和启动状态下的颜色
contentPadding
内容内间距
TextButton¶
TextButton
一般是用来显示文字按钮的
@Composable
fun ButtonSample() {
TextButton(
onClick = {
Log.d("ButtonSample", "click the button")
},
) {
Text(text = "TextButton")
}
}
OutlinedButton¶
@Composable
fun ButtonSample() {
OutlinedButton(
onClick = {
Log.d("ButtonSample", "click the button")
},
) {
Text(text = "OutlinedButton")
}
}
IconButton¶
用来显示图标按钮
@Composable
fun ButtonSample() {
IconButton(
onClick = {
Log.d("ButtonSample", "click the button")
},
) {
Icon(imageVector = Icons.Default.Stairs, contentDescription = null)
}
}