@Retention(value = AnnotationRetention.BINARY)
@Target(allowedTargets = [AnnotationTarget.ANNOTATION_CLASS, AnnotationTarget.FUNCTION])
@Repeatable
@MustBeDocumented
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(
    name: String,
    group: String,
    locale: String,
    device: String,
    fontScale: @FloatRange(from = 0.01) Float
)

Public properties

String

Device identifier indicating the device to use in the preview.

Float

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

String

Group name for this @Preview.

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.

Public constructors

Preview

Preview(
    name: String = "",
    group: String = "",
    locale: String = "",
    device: String = WearDevices.SMALL_ROUND,
    fontScale: @FloatRange(from = 0.01) Float = 1.0f
)
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 displaying only one or more of them.

locale: String = ""

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

device: String = WearDevices.SMALL_ROUND

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

fontScale: @FloatRange(from = 0.01) Float = 1.0f

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

Public properties

device

val deviceString

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

fontScale

val fontScaleFloat

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

group

val groupString

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

locale

val localeString

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

name

val nameString

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