Compose预览-@Preview用法

示例.png

用法:

  1. 一个文件可以有多个Composable添加@Preview,预览面板可以同时看到
  2. 支持的部分参数:
//  设置预览的界面带有背景颜色
@Preview(showBackground = true, backgroundColor = 0xFF00FF00)
// 设置预览的界面大小
@PreView(widthDp = 50, heightDp = 50)
// 设置预览的语言
@Preview(locale - "fr-rFR")
// 显示状态栏
@Preview(showSystemUi = true)
// 启动夜间模式
@Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES)
// Pixel 设备中预览
@Preview(device = Devices.PIXEL)

tip:

  • Composable有参数且缺少默认值时无法预览
  • 预览效果编译之后才会生效
  • 动态预览模式可以直接预览动画、测试手势交互。
  • 支持将当前预览页面像App一样运行到手机或模拟器上。

你可能感兴趣的:(Compose预览-@Preview用法)