标签:image ble https cimage option test kotlin 源代码 field
Jetpack Compose是什么?Jetpack Compose 是安卓用于构建UI的一种新方式,采用代码而非xml文件方式,写法与Flutter非常相似。
官方主页:https://developer.android.google.cn/jetpack/compose
官方Demo:https://github.com/android/compose-samples/tree/master/JetNews
官方入门指导:?https://developer.android.google.cn/jetpack/compose/tutorial
Text(text = "众鸟高飞尽,孤云独去闲。相看两不厌,只有敬亭山。")
val state = +state { "Text Field to input" }
TextField(
value = state.value,
onValueChange = { state.value = it }
)
Button(text = "咬我啊", onClick = { Log.v("test", "被咬了") })
4.弹出框
MaterialTheme {
Column {
val openDialog = +state { false }
Button("Click me", onClick = {
openDialog.value = true
})
if (openDialog.value) {
AlertDialog(
onCloseRequest = {
openDialog.value = false
},
title = {
Text(text = "Alert Dialog Title")
},
text = {
Text("Alert Dialog content")
},
confirmButton = {
Button(
"Confirm",
onClick = {
openDialog.value = false
})
},
dismissButton = {
Button(
"Cancel",
onClick = {
openDialog.value = false
})
},
buttonLayout = AlertDialogButtonLayout.Stacked
)
}
}
}
MaterialTheme {
val checkedState = +state { true }
Switch(
checked = checkedState.value,
onCheckedChange = { checkedState.value = it }
)
}
MaterialTheme {
RadioButton(selected = true,
onSelect = { }
)
}
MaterialTheme {
val checkedState = +state { true }
Checkbox(
checked = checkedState.value,
onCheckedChange = { checkedState.value = it }
)
}
MaterialTheme {
val radioOptions = listOf("A", "B", "C")
val (selectedOption, onOptionSelected) = +state { radioOptions[0] }
RadioGroup(
options = radioOptions,
selectedOption = selectedOption,
onSelectedChange = onOptionSelected
)
}
9.图片
Container(modifier = Height(300.dp) wraps Expanded) {
Clip(shape = RoundedCornerShape(4.dp)) {
DrawImage(+imageResource(R.drawable.img_0))
}
}
https://github.com/cxyzy1/Jetpack-Compose-Demos
文章不易,如果大家喜欢这篇文章,或者对你有帮助希望大家多多,点赞,转发,关注?哦。文章会持续更新的。绝对干货!!!
阿里大牛又一波骚操作,安卓UI开发新技能-Jetpack Compose,绝了
标签:image ble https cimage option test kotlin 源代码 field
原文地址:https://blog.51cto.com/14775360/2486302