抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >

使用 JetpackCompose 的一些笔记。

关键术语 - 组合:Jetpack Compose 在执行可组合项时构建的界面描述。
初始组合:通过首次运行可组合项创建组合。
重组:在数据发生变化时重新运行可组合项以更新组合。

'Surface' A surface container using the 'background' color from the theme

'Divider' is a provided composable function that creates a horizontal divider.

可组合项中的状态

可组合函数可以使用 remember 可组合项记住单个对象。

系统会在初始组合期间将由 remember 计算的值存储在组合中,并在重组期间返回存储的值。

  • remember 既可用于存储可变对象,又可用于存储不可变对象。
  • mutableStateOf 会创建可观察的 MutableState 会创建可观察的 MutableState,后者是与 Compose 运行时集成的可观察类型。

在可组合项中声明 MutableState 对象的方法有三种(等价):

  • val mutableState = remember { mutableStateOf(default) }
  • var value by remember { mutableStateOf(default) }
  • val (value, setValue) = remember { mutableStateOf(default) }
1
2
3
4
5
6
7
@Composable
fun Counter() {
val count = remember { mutableStateOf(0) }
Button(onClick = { count.value++ }) {
Text("I've been clicked ${count.value} times")
}
}

Color

Material Design Color
  • primary:main brand color
  • secondary:provide accents

Typography

Typographies

评论



Modify from Volantis theme Powered by Hexo