{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

Preview

@MustBeDocumented
@Retention(value = AnnotationRetention.BINARY)
@Target(allowedTargets = [AnnotationTarget.ANNOTATION_CLASS, AnnotationTarget.FUNCTION])
@Repeatable
public annotation Preview


Preview can be applied to either of the following:

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

Preview(
    @NonNull String name,
    @NonNull String group,
    @IntRange(from = 1) int apiLevel,
    int widthDp,
    int heightDp,
    @NonNull String locale,
    @FloatRange(from = 0.01) float fontScale,
    boolean showSystemUi,
    boolean showBackground,
    long backgroundColor,
    int uiMode,
    @Device @NonNull String device,
    @Wallpaper int wallpaper
)

Public methods

final int

API level to be used when rendering the annotated @Composable

final long

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

final @NonNull String

Device string indicating the device to use in the preview.

final float

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

final @NonNull String

Group name for this @Preview.

final int

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

final @NonNull String

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

final @NonNull String

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

final boolean

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

final boolean

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

final int

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

final int

Integer defining which wallpaper from those available in Android Studio to use for dynamic theming.

final int

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

Public constructors

Preview

public Preview(
    @NonNull String name,
    @NonNull String group,
    @IntRange(from = 1) int apiLevel,
    int widthDp,
    int heightDp,
    @NonNull String locale,
    @FloatRange(from = 0.01) float fontScale,
    boolean showSystemUi,
    boolean showBackground,
    long backgroundColor,
    int uiMode,
    @Device @NonNull String device,
    @Wallpaper int wallpaper
)
Parameters
@NonNull String name

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

@NonNull String group

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

@IntRange(from = 1) int apiLevel

API level to be used when rendering the annotated @Composable

int widthDp

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

int heightDp

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

@NonNull String locale

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

@FloatRange(from = 0.01) float fontScale

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

boolean showSystemUi

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.

boolean showBackground

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

long backgroundColor

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

int uiMode

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

@Device @NonNull String device

Device string indicating the device to use in the preview. See the available devices in Devices.

@Wallpaper int wallpaper

Integer defining which wallpaper from those available in Android Studio to use for dynamic theming.

Public methods

getApiLevel

public final int getApiLevel()

API level to be used when rendering the annotated @Composable

getBackgroundColor

public final long getBackgroundColor()

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

getDevice

public final @NonNull String getDevice()

Device string indicating the device to use in the preview. See the available devices in Devices.

getFontScale

public final float getFontScale()

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

getGroup

public final @NonNull String getGroup()

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

getHeightDp

public final int getHeightDp()

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

getLocale

public final @NonNull String getLocale()

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

getName

public final @NonNull String getName()

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

getShowBackground

public final boolean getShowBackground()

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

getShowSystemUi

public final boolean getShowSystemUi()

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.

getUiMode

public final int getUiMode()

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

getWallpaper

public final int getWallpaper()

Integer defining which wallpaper from those available in Android Studio to use for dynamic theming.

getWidthDp

public final int getWidthDp()

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