I'm a Android beginner and I'm getting started with Jetpack Compose. I'm confused about these two set files created by new Compose project template: themes.xml
vs Theme.kt
, and colors.xml
vs Color.kt
. Both colors.xml
and Color.kt
contain color definitions, and both themes.xml
and Theme.kt
contain primary color definition.
What's the difference between the XML file and the Kotlin file? Am I supposed to manually sync their contents?
CodePudding user response:
What's the difference between the XML file and the Kotlin file?
By default, android uses the XML files for setting the theme ... If you are using the compose (which is obviously you are doing) then you need to set theme like this
setContent {
AppThemeName { //AppThemeName is the name of your theme .. its autogenerated at the beginning by AppName Theme
}
}
Compose uses Theme.kt
to get the theme information and similarly Color.kt
for colors
Am I supposed to manually sync their contents?
No, But It depends ... generally if you are using only compose throughout your app then you don't need to manually sync the XML file since the Theme.kt file has the theme information that you will be using.
But there are cases where you need to mention some attributes in theme.xml for example windowSplashScreenAnimatedIcon, statusBarColor
which cant be defined by default in compose Theme.kt