https://kotlinlang.org logo
Title
c

Colton Idle

04/14/2022, 10:49 PM
I know this was discussed a bit before (i remember talking about it in the dev preview) but did anything ever update from what the default theme should be for a compose only app? I currently use
<style name="Theme.My.App" parent="android:Theme.Material.NoActionBar" />
I think Chris Banes was talking about this sort of stuff last, but yeah. Just curious if theres a way to use non-appcompat theme (so no appcompat dependency) but have a DayNight theme? because I don't want to bring in appcompat, but it looks like Theme.Material.* doesn't have any daynight variation. I think
a

andrew

04/14/2022, 11:02 PM
Realistically, you can use v21 Material since compose is v21+, just setting up day/night resource qualifiers
c

Colton Idle

04/14/2022, 11:07 PM
Wouldn't that mean that my launch theme/androidx.splash screen can't adapt to day night though? right now if i launch my app, the bright white in the launch theme is blinding even though the phone is in night mode. I was able to fix that when using appcompat dayNight
So now my design team has a bug opened against my app, and im not sure what to do. 🙃
a

andrew

04/14/2022, 11:07 PM
Create day/night resource qualifiers for that too
That’s what I’m doing anyway
<style name="Theme.RealPage.Raul.Base" parent="Theme.AppCompat.DayNight.NoActionBar">
        <item name="android:windowBackground">#FFFFFFFF</item>
        <item name="android:windowLightStatusBar" tools:targetApi="m">true</item>
        <item name="android:windowLightNavigationBar" tools:targetApi="o_mr1">true</item>
    </style>

    <style name="Theme.RealPage.Raul" parent="Theme.RealPage.Raul.Base">
        <item name="android:statusBarColor">@android:color/transparent</item>
        <item name="android:navigationBarColor">@android:color/transparent</item>
    </style>

    <style name="Theme.RealPage.Raul.Splash" parent="Theme.SplashScreen">
        <item name="postSplashScreenTheme">@style/Theme.RealPage.Raul</item>
        <item name="windowSplashScreenBackground">#FFFFFFFF</item>
        <item name="android:windowSplashScreenBrandingImage" tools:targetApi="s">@drawable/ui_splash_realpage_logo</item>

        <item name="android:statusBarColor">@android:color/transparent</item>
        <item name="android:navigationBarColor">@android:color/transparent</item>

        <item name="android:windowLightStatusBar" tools:targetApi="m">true</item>
        <item name="android:windowLightNavigationBar" tools:targetApi="o_mr1">true</item>
    </style>
<style name="Theme.RealPage.Raul.Base" parent="Theme.AppCompat.DayNight.NoActionBar">
        <item name="android:windowBackground">#FF202737</item>
        <item name="android:windowLightStatusBar" tools:targetApi="m">false</item>
        <item name="android:windowLightNavigationBar" tools:targetApi="o_mr1">false</item>
    </style>

    <style name="Theme.RealPage.Raul.Splash" parent="Theme.SplashScreen">
        <item name="postSplashScreenTheme">@style/Theme.RealPage.Raul</item>
        <item name="windowSplashScreenBackground">#FF202737</item>
        <item name="android:windowSplashScreenBrandingImage" tools:targetApi="s">@drawable/ui_splash_realpage_logo</item>

        <item name="android:windowLightStatusBar" tools:targetApi="m">false</item>
        <item name="android:windowLightNavigationBar" tools:targetApi="o_mr1">false</item>
    </style>
c

Colton Idle

04/14/2022, 11:09 PM
But you're using AppCompat?
I don't have appCompat in my app.
a

andrew

04/14/2022, 11:09 PM
You can swap that out for Theme.Material
c

Colton Idle

04/14/2022, 11:10 PM
That's what I'm saying though. Theme.Material doesn't have DayNight.
Unless Im missing something here...
a

andrew

04/14/2022, 11:11 PM
Define your base theme in both values and values-night
And the parent will be Theme.Material.Light for normal values
And for values-night use Theme.Material
c

Colton Idle

04/14/2022, 11:11 PM
Ah gotcha. Lemme try to check that out when I get back to my desk.
a

andrew

04/14/2022, 11:12 PM
Cool beans 👍🏻
c

Chris Sinco [G]

04/15/2022, 12:47 AM
You can also depend on the Material library for views which has DayNight themes: https://material.io/develop/android/theming/dark
Because yeah, I've seen that bright flash as well without a proper Activity theme mapped to some dark colors 😬
c

Colton Idle

04/15/2022, 12:49 AM
Interesting. So out of the box tho. For compose there's no daynight theme available. Maybe I'll file a bug. I kinda don't know if it's purposeful or not from the Android team I suppose
a

andrew

04/15/2022, 12:50 AM
Compose itself is independent of the view system, so there is no theme there
You can use whatever theme you need to, tailoring it to how you need to suit your app
c

Colton Idle

04/15/2022, 2:42 AM
Cool. So it seems like nothing has really changed on this front.
a

Albert Chang

04/15/2022, 2:45 AM
Even if a DayNight theme is added now, it can only be used on Android 13+ as it must be added to Android platform itself instead of a support library.
✔️ 1
c

Colton Idle

04/15/2022, 5:04 PM
Ah. alright.
android:
means it comes from the platform?
has material been around that long already?
a

andrew

04/15/2022, 8:11 PM
Yes, since Lolipop, so around 2014
c

Colton Idle

04/19/2022, 3:49 AM
wow. so material is around for 50% of androids lifetime roughly. insane. time flies!!!