The Developer Preview for Android 11 is now available; test it out and share your feedback.

Preview

@Target([AnnotationTarget.FUNCTION]) annotation class Preview
androidx.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 = "", apiLevel: Int = -1, theme: String = "", widthDp: Int = -1, heightDp: Int = -1, locale: String = "", fontScale: Float = 1f, showDecoration: Boolean = false, showBackground: Boolean = false)

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

Inherited extension functions

From androidx.compose
operator T

IMPORTANT: This global operator is TEMPORARY, and should be removed whenever an answer for contextual composers is reached.

Properties

Int

API level to be used when rendering the annotated @Composable

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.

String

Theme name to be used when rendering the annotated @Composable

Int

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

Public constructors

<init>

Preview(
    name: String = "",
    group: String = "",
    apiLevel: Int = -1,
    theme: String = "",
    widthDp: Int = -1,
    heightDp: Int = -1,
    locale: String = "",
    fontScale: Float = 1f,
    showDecoration: Boolean = false,
    showBackground: Boolean = false)

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
theme: String = "" Theme name to be used when rendering the annotated @Composable
widthDp: Int = -1 Max width in DP the annotated @Composable will be rendered in. Use this to restrict the size of the rendering viewport.
heightDp: Int = -1 Max height in DP the annotated @Composable will be rendered in. Use this to restrict the size of the rendering viewport.
locale: String = "" Current user preference for the locale, corresponding to locale resource qualifier. By default, the default folder will be used.
fontScale: Float = 1f User preference for the scaling factor for fonts, relative to the base density scaling.
showDecoration: Boolean = false If true, the status bar and action bar of the device will be displayed. The @Composable will be render in the context of a full activity.
showBackground: Boolean = false If true, the @Composable will use a default background color.

Properties

apiLevel

val apiLevel: Int

API level to be used when rendering the annotated @Composable

fontScale

val fontScale: Float

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

group

val group: String

Group name for this @Preview. This allows grouping them in the UI and display only one or more of them.

heightDp

val heightDp: Int

Max height in DP the annotated @Composable will be rendered in. Use this to restrict the size of the rendering viewport.

locale

val locale: String

Current user preference for the locale, corresponding to locale resource qualifier. By default, the default folder will be used.

name

val name: String

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

showBackground

val showBackground: Boolean

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

showDecoration

val showDecoration: Boolean

If true, the status bar and action bar of the device will be displayed. The @Composable will be render in the context of a full activity.

theme

val theme: String

Theme name to be used when rendering the annotated @Composable

widthDp

val widthDp: Int

Max width in DP the annotated @Composable will be rendered in. Use this to restrict the size of the rendering viewport.