Android Weekly Notes

Android Weekly Notes #501

2022-04-07  本文已影响0人  圣骑士wind

Android Weekly Issue #501

Jetpack Compose: Preview

@Preview的基本用法是无参数的.

还可以用它:

基本使用

可以给一个composable function加多个@preview:

@Preview(locale = "en", showBackground = true)
@Preview(locale = "ru", showBackground = true)
@Preview(locale = "ar", showBackground = true)
@Composable
fun Preview_CoffeeDrinkItem() {
    CoffeeDrinkItem(
        title = stringResource(R.string.espresso_title),
        ingredients = stringResource(R.string.espresso_ingredients),
        icon = R.drawable.espresso_small
    )
}

@Preview的各个参数的用途.
居然还有简单的互动模式.

进阶使用

@PreviewParameter来提供参数(用于preview的数据).

后面讲了各种配置的排列组合.

screenshot test

推荐了: Showkase

另一种方案是Shot

Exploring Material You for Jetpack Compose

新一代的material design: Material You.

其中一个重要的元素是动态颜色系统, 可以根据用户的壁纸build出一个color scheme.

compose-material3:
https://developer.android.com/jetpack/androidx/releases/compose-material3

本篇文章也有个demo.

Analyze Stack Traces in Android Studio

Code

上一篇下一篇

猜你喜欢

热点阅读