0
0
Android Kotlinmobile~5 mins

Preview annotation in Android Kotlin - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the @Preview annotation in Android Jetpack Compose?
The @Preview annotation lets you see a live preview of a composable function in Android Studio without running the app on a device or emulator. It helps you quickly check UI changes.
Click to reveal answer
intermediate
How do you specify the device size or theme in a @Preview annotation?
You can add parameters like device = "specs" or uiMode = Configuration.UI_MODE_NIGHT_YES inside @Preview to simulate different screen sizes or dark mode in the preview.
Click to reveal answer
intermediate
Can you preview a composable function that takes parameters using @Preview?
No, @Preview only works on parameterless composable functions. To preview composables with parameters, create a wrapper composable without parameters that calls it with sample data.
Click to reveal answer
advanced
What happens if you add multiple @Preview annotations to a single composable function?
Android Studio shows multiple previews side by side, each with the different settings specified in each @Preview. This helps compare UI in different configurations easily.
Click to reveal answer
beginner
Why is using @Preview annotation helpful during UI development?
It speeds up UI design by showing instant visual feedback without needing to build and run the app. This saves time and helps catch layout issues early.
Click to reveal answer
What does the @Preview annotation do in Jetpack Compose?
AShows a live preview of a composable in Android Studio
BRuns the app on a physical device
CCompiles the app faster
DGenerates XML layouts automatically
Which of these is NOT a valid parameter for @Preview?
AshowBackground
Bdevice
CuiMode
DonClick
How can you preview a composable that requires parameters?
AAdd <code>@Preview</code> directly to it
BCreate a parameterless wrapper composable calling it with sample data
CUse XML preview instead
DYou cannot preview composables with parameters
What happens if you add multiple @Preview annotations to one composable?
AOnly the first preview is shown
BAndroid Studio crashes
CMultiple previews appear side by side
DThe previews overwrite each other
Why is @Preview useful for beginners learning Compose?
AIt shows UI changes instantly without running the app
BIt automatically fixes code errors
CIt generates documentation
DIt replaces the need for an emulator
Explain how to use the @Preview annotation to see your composable UI in Android Studio.
Think about how you can check your UI without running the app.
You got /4 concepts.
    Describe how you would preview a composable function that needs input parameters.
    You can’t preview functions with parameters directly.
    You got /4 concepts.