0
0
Android Kotlinmobile~10 mins

Preview annotation in Android Kotlin - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add a preview annotation for a composable function.

Android Kotlin
@[1]
@Composable
fun Greeting() {
    Text("Hello, World!")
}
Drag options to blanks, or click blank then click option'
AOverride
BComposable
CMainActivity
DPreview
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Composable instead of @Preview for previewing.
Forgetting the '@' symbol before the annotation.
2fill in blank
medium

Complete the code to specify the device for the preview annotation.

Android Kotlin
@Preview(device = "[1]")
@Composable
fun Greeting() {
    Text("Hello, World!")
}
Drag options to blanks, or click blank then click option'
Aiphone_12
Bpixel_5
Cdesktop
Dtablet
Attempts:
3 left
💡 Hint
Common Mistakes
Using device names that are not supported like 'desktop'.
Not using quotes around the device name.
3fill in blank
hard

Fix the error in the preview annotation to show the composable with a background color.

Android Kotlin
@Preview(showBackground = [1])
@Composable
fun Greeting() {
    Text("Hello, World!")
}
Drag options to blanks, or click blank then click option'
ATrue
B"true"
Ctrue
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using "true" as a string instead of true Boolean.
Using capitalized True which is invalid in Kotlin.
4fill in blank
hard

Fill both blanks to create a preview with a custom name and background shown.

Android Kotlin
@Preview(name = "[1]", showBackground = [2])
@Composable
fun Greeting() {
    Text("Hello, World!")
}
Drag options to blanks, or click blank then click option'
ADefault Preview
Btrue
Cfalse
DGreeting Preview
Attempts:
3 left
💡 Hint
Common Mistakes
Using false for showBackground when background is needed.
Not quoting the name string.
5fill in blank
hard

Fill all three blanks to create a preview with a specific device, show background, and set a custom name.

Android Kotlin
@Preview(device = "[1]", showBackground = [2], name = "[3]")
@Composable
fun Greeting() {
    Text("Hello, World!")
}
Drag options to blanks, or click blank then click option'
Apixel_4
Bfalse
CMy Greeting Preview
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using false instead of true for showBackground.
Not quoting device or name strings.