https://kotlinlang.org logo
#compose
Title
# compose
v

Vitor Prado

01/20/2021, 3:36 PM
which theme should be used in manifest? I need to create a light and a dark theme in xml too? or compose has a default for that?
o

Oussama Haff.

01/20/2021, 3:42 PM
There is no need to declare anything in the manifest. Please take a look at this sample app from Google to see how dark/light theme is set in Compose https://github.com/android/compose-samples/blob/main/JetNews/app/src/main/java/com/example/jetnews/ui/theme/Theme.kt
v

Vitor Prado

01/20/2021, 3:44 PM
@Oussama Haff. thanks for the reference.. but looking into the manifest file, there is a declaration of themes and colors for light/dark themes: https://github.com/android/compose-samples/blob/main/JetNews/app/src/main/AndroidManifest.xml
o

Oussama Haff.

01/20/2021, 4:00 PM
AFAIK, the declaration in the manifest is needed because the Activity still need to use Theme.AppCompat for Android (or you get a runtime exception). whereas Compose Theme applies the theme on the content inside of the activity on the descendants of
setContent { }
function / This is my personal interpretation of things /
a

Adam Powell

01/20/2021, 4:02 PM
nah, you don't have to use Theme.AppCompat. You could just as easily use the on-device android:Theme.Material. The only thing you have to use a static theme for is for the, "starting window" that Android displays before your activity code starts running.
👍 1
so you could imagine why you might want to make that light/dark aware; you wouldn't want someone using the app in dark mode to get a sudden bright flash on their screen when your app first loads.
(You can write an entire compose app without including the appcompat library at all)
👍 2
j

Javier

01/20/2021, 4:59 PM
Preview annotation uses the manifest theme?
n

nickbutcher

01/20/2021, 10:58 PM
Here's an example commit which switched one of our samples from AppCompat to a platform material theme, notice how it inherits from light/dark parents: https://github.com/android/compose-samples/commit/bbe9436cfa4d0ea177af499a21d4b51d1b801c30#diff-dffd6e3920461da2ef29b76429ba730410298a65ed2cf537bdd75374a61b50bf
🙌 2
3 Views