当您在Android中创建一个新项目时,选择模板Jetpack Compose Material3,您将得到一个在themes.xml中定义如下的项目:
<style name="Theme.ComposeMaterial3" parent="android:Theme.Material.Light.NoActionBar" />参考Material3样式?(ComposeMaterial3Theme)
为什么不将此设置为父"Theme.Material3..."?
发布于 2022-11-04 07:34:04
在您的应用程序中,您可以定义更多的组合主题(例如在Theme.kt文件中)。
要应用其中之一,您必须用最喜欢的主题包装您的可组合材料。
例如:
setContent {
MyCustomM3Theme {
//...your composables
}
}关于xml中定义的主题,可以扩展M3主题,例如:Theme.Material3.Light.NoActionBar
<style name="Theme.ComposeMaterial3" parent="Theme.Material3.Light.NoActionBar" />但是可组合的不使用 it。他们用作曲的主题。
themes.xml中定义的主题用于材料组件库(以及其他小部件作为状态栏)。
为什么不将其设置为父级“Theme.Material3.”?
您的主题被定义为:
@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
)
}MaterialTheme在包androidx.compose.material3中定义。
发布于 2022-11-04 08:11:43
https://stackoverflow.com/questions/74313135
复制相似问题