When you create a new project in Android Studio selecting the template Jetpack Compose Material3 you get a project which defines following in themes.xml:
<style name="Theme.ComposeMaterial3" parent="android:Theme.Material.Light.NoActionBar" />
Is this being used by the project at all since the Composables
reference Material3 styles? (ComposeMaterial3Theme)Why does this not set as parent "Theme.Material3..."?
CodePudding user response:
In your app you can define more compose themes (for example in the Theme.kt
file).
To apply one of them you have to wrap your composables with the favorite theme.
For example:
setContent {
MyCustomM3Theme {
//...your composables
}
}
About the theme defined in the xml, you can extend a M3 theme for example: Theme.Material3.Light.NoActionBar
<style name="Theme.ComposeMaterial3" parent="Theme.Material3.Light.NoActionBar" />
but the composables don't use it. They use the compose theme.
The theme defined in the themes.xml
is used in the material components library.
Why does this not set as parent "Theme.Material3..."?
Your theme is defined as:
@Composable
fun MyCustomM3Theme(
darkTheme: Boolean = isSystemInDarkTheme(),
// Dynamic color is available on Android 12
dynamicColor: Boolean = true,
content: @Composable () -> Unit
) {
//...
MaterialTheme( //<---
colorScheme = colorScheme,
typography = Typography,
content = content
)
}
The MaterialTheme
is defined in the package androidx.compose.material3
CodePudding user response:
Yes, it's being used. The app itself can still use xml themes for things like the status bar colour, and the app icon. A good example project is https://github.com/android/compose-samples/tree/main/Jetchat. You can see how they achieve the "material you" styling for multiple android versions using the Material3 theme in that project.
That would be a question for the template designer. In my opinion, if you look at the volume of theme based configuration required in JetChat to achieve consistent theming across multiple Android versions, I can believe that the Compose Material3 template is trying to keep things a bit more simple to highlight the concepts of material 3 in Compose. (Absolutely no evidence to back that up though).