吴景华技术博客 记录、分享经验

compositionLocalOf和viewModel

由于被NavHost(会为每个导航目标创建NavBackStackEntry从而导致不同的生命周期和作用域)包裹后Composable页面无法通过viewModel()得到Activity中的相同实例,所以使用CompositionLocalOf显式传递。 由于NavBackStackEntry每个

Administrator Published on 2025-03-21

自定义带过渡效果的主题

切换主题时有过渡效果。 // theme.kt import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setVa

Administrator Published on 2025-03-20

注解Annotation

Composable 可组合元素/页面 @Composable fun ProfileScreen() { val nav = localNavController.current var i1 by rememberSaveable { mutableStateOf("") }

Administrator Published on 2025-03-20

ImageVector、Painter、Bitmap

Painter painterResource(R.drawable.ic_launcher_foreground) //从res/drawable目录读取资源ID读为Painter val customVector = ImageVector.Builder( name

Administrator Published on 2025-03-19

环境&构建&编绎

安装Flutter SDK和配置基础环境 下载页面:https://docs.flutter.cn/get-started/install/windows/mobile#install-the-flutter-sdk 选择Stable稳定版下载,下载好之后的zip解压到目录中,如:D:\Soft\F

Administrator Published on 2025-03-14

navigation(页面路由)

依赖项网页:https://developer.android.com/jetpack/androidx/releases/navigation?hl=zh-cn#declaring_dependencies 引入依赖 dependencies { val nav_version = "2.8.

Administrator Published on 2025-03-13

Modifier

一个用于修饰元素样式和行为的类,它属于compose开发中最重要的东西之一 调用顺序的不同效果 Text("test", Modifier.background(Color.Red).padding(20.dp)) //先设置背景色,再向四周撑开20dp。(文字区域+四周的20dp有底色) Text

Administrator Published on 2025-01-17
Administrator Published on 2024-12-22

Modifier绘制角标

代码现实了可拖拽的数字角标,拖动距离大于某个数值时丢弃(清理未读内容) //将方法放在Modifier类上,就可以在全局任意位置使用 //以下注释假设传入的tag:Int为25 fun Modifier.unread(offset: Offset, tag: Int): Modifier = th

Administrator Published on 2024-12-22
Previous Next