Android 12 Developer Preview is here! Try it out, and give us your feedback!

Preview

@Target([AnnotationTarget.FUNCTION]) annotation class Preview
androidx.compose.ui.tooling.preview.Preview

Preview can be applied to @Composable methods with no parameters to show them in the Android Studio preview.

The annotation contains a number of parameters that allow to define the way the @Composable will be rendered within the preview.

The passed parameters are only read by Studio when rendering the preview.

Summary

Public constructors
<init>(name: String = "", group: String = "", @IntRange(1) apiLevel: Int = -1, widthDp: Int = -1, heightDp: Int = -1, locale: String = "", @FloatRange(0.01) fontScale: Float = 1f, showSystemUi: Boolean = false, showBackground: Boolean = false, backgroundColor: Long = 0, uiMode: Int = 0, device: String = Devices.DEFAULT)

Preview can be applied to @Composable methods with no parameters to show them in the Android Studio preview.

Properties
Int

API level to be used when rendering the annotated @Composable

Long

The 32-bit ARGB color int for the background or 0 if not set

String

Device string indicating the device to use in the preview.

Float

User preference for the scaling factor for fonts, relative to the base density scaling.

String

Group name for this @Preview.

Int

Max height in DP the annotated @Composable will be rendered in.

String

Current user preference for the locale, corresponding to locale resource qualifier.

String

Display name of this preview allowing to identify it in the panel.

Boolean

If true, the @Composable will use a default background color.

Boolean

If true, the status bar and action bar of the device will be displayed.

Int

Bit mask of the ui mode as per android.content.res.Configuration.uiMode

Int

Max width in DP the annotated @Composable will be rendered in.

Public constructors

<init>

Preview(
    name: String = "",
    group: String = "",
    @IntRange(1) apiLevel: Int = -1,
    widthDp: Int = -1,
    heightDp: Int = -1,
    locale: String = "",
    @FloatRange(0.01) fontScale: Float = 1f,
    showSystemUi: Boolean = false,
    showBackground: Boolean = false,
    backgroundColor: Long = 0,
    uiMode: Int = 0,
    device: String = Devices.DEFAULT)

Preview can be applied to @Composable methods with no parameters to show them in the Android Studio preview.

The annotation contains a number of parameters that allow to define the way the @Composable will be rendered within the preview.

The passed parameters are only read by Studio when rendering the preview.

Parameters
name: String = "" Display name of this preview allowing to identify it in the panel.
group: String = "" Group name for this @Preview. This allows grouping them in the UI and display only one or more of them.
apiLevel: Int = -1 API level to be used when rendering the annotated @Composable
widthDp: Int = -1 Max width in DP the annotated @