Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Composable instead of @Preview for previewing.
Forgetting the '@' symbol before the annotation.
✗ Incorrect
The @Preview annotation allows you to see the composable function in Android Studio's preview window.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using device names that are not supported like 'desktop'.
Not using quotes around the device name.
✗ Incorrect
The device parameter specifies which device to simulate in the preview. 'pixel_5' is a valid device name.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using "true" as a string instead of true Boolean.
Using capitalized True which is invalid in Kotlin.
✗ Incorrect
The showBackground parameter expects a Boolean value true or false without quotes.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using false for showBackground when background is needed.
Not quoting the name string.
✗ Incorrect
The name parameter is a string for the preview label, and showBackground is a Boolean true to show background.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using false instead of true for showBackground.
Not quoting device or name strings.
✗ Incorrect
Use 'pixel_4' as device string, true Boolean for showBackground, and a descriptive string for name.