I am following https://developer.android.com/jetpack/compose/tutorial
and the code
@Preview(name = "Light Mode")
@Preview(name = "Dark Mode", uiMode = Configuration.UI_MODE_NIGHT_UNDEFINED, showBackground = true)
@Preview(name = "Full Preview", showSystemUi = true)
@Composable
fun DefaultPreview() {
ComposeTutorialTheme {
MessageCard(Message("Roman", "message body"))
}
}

It "works" in the tutorial because they use a
Cardwhich uses aSurfaceunder the hood.The dark background you are seeing is not produced by the
@Previewannotation, but rather by theSurfacewhich simply draws its own background based on theMaterialTheme.Barebones implementation of
Surface:Surfacealso overrides the "content color" withso that the text or icons displayed within the
Surfacecontrast well with the background color.You still have to set up the
MaterialThemeto follow the dark theme. Finally, the preview composable would looks something like this:Here is a comparison of how previews like look when you forget to use a
Card/Surfaceor do not apply anisSystemInDarkTheme()-awareMaterialTheme: