PreviewThemes
annotation class PreviewThemes
Multi-preview annotation for testing Composables in light and dark themes.
Applying this annotation automatically generates preview variants for both light and dark UI modes, ensuring your components look correct in all theme configurations.
Usage
@PreviewThemes
@Composable
fun MyButtonPreview() {
JetpackTheme {
Surface {
MyButton(
text = "Click Me",
onClick = {}
)
}
}
}Content copied to clipboard
Best Practices
Always wrap previews in
JetpackThemeto test theme colorsUse
Surfacefor components that need a backgroundCombine with
@PreviewDevicesto test themes across device sizes
Combining Multiple Preview Annotations
@PreviewThemes
@PreviewDevices
@Composable
fun ComprehensivePreview() {
JetpackTheme {
MyScreen(/* ... */)
}
}
// Generates 8 previews: 4 devices × 2 themesContent copied to clipboard