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


The annotation that marks Tile preview components that should have a visual preview in the Android Studio preview panel. Tile preview components are methods that take an optional Context parameter and return a TilePreviewData. Methods annotated with Preview must be top level declarations or in a top level class with a default constructor.

For example:

@Preview
fun
myTilePreview(): TilePreviewData {
return TilePreviewData { request -> myTile(request) }
}

or:

@Preview
fun
myTilePreview(context: Context): TilePreviewData {
return TilePreviewData { request -> myTile(request, context) }
}

Because of the way previews are rendered within Android Studio, they are lightweight and don't require the whole Android framework to render them. However, this comes with the following limitations:

  • No network access

  • No file access

  • Some Context APIs may not be fully available, such as launching activities or retrieving services

For more information, see https://developer.android.com/jetpack/compose/tooling/previews#preview-limitations

The annotation contains a number of parameters that allow to define the way the Tile 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,
    @NonNull String locale,
    @NonNull String device,
    @FloatRange(from = 0.01) float fontScale
)

Public methods

final @NonNull String

Device identifier indicating the device to use in the preview.

final float

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

final @NonNull String

Group name for this @Preview.

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.

Public constructors

Preview

public Preview(
    @NonNull String name,
    @NonNull String group,
    @NonNull String locale,
    @NonNull String device,
    @FloatRange(from = 0.01) float fontScale
)
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 displaying only one or more of them.

@NonNull String locale

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

@NonNull String device

Device identifier indicating the device to use in the preview. For example "id:wearos_small_round".See the available devices in WearDevices.

@FloatRange(from = 0.01) float fontScale

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

Public methods

getDevice

public final @NonNull String getDevice()

Device identifier indicating the device to use in the preview. For example "id:wearos_small_round".See the available devices in WearDevices.

getFontScale

public final float getFontScale()

User preference for the linear 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 displaying only one or more of them.

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.