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

Chris Johnson

08/01/2022, 9:18 PM
Is there a way to change statusBar/navigationBar colors in a launcherActivity via something in compose? Or is this just something that needs to be done on the Activity level via styles. Currently if I use accompanist when setting up my themes to try and switch the colors you notice initially they default to the MaterialTheme. (which makes sense. My composable theme hasn't been invoked yet) Guess I was wondering if there's a way to apply your compose themes and set those as the source of truth before the activity default theme comes into play? For instance I'd like to set the status/nav bar to transparent on my launcher activity
a

Alex Vanyo

08/01/2022, 9:37 PM
The theme attributes should apply first, so you can set those in the theme to begin with, and then modify them later (if needed) programmatically. There probably is an argument to be made that you could handle that entirely outside of composition (in something like
Activity.onCreate
directly) to ensure you’re setting them as quickly as possible, but driven by the same state that decides your theme in Compose.
c

Chris Johnson

08/01/2022, 9:40 PM
Gotcha. Yeah I was just trying to potentially eliminate the need for
styles.xml
entirely. If I understand you correctly though it seems we need it as a baseline(either via setting it on the window in the
Activity.onCreate
or via styles) to be changed later on in composition. Totally fine, just wanted to be sure there wasn't a better recommended approach 🙂 Thanks for the response!
a

Alex Vanyo

08/01/2022, 9:56 PM
Yeah, for some of these system-level things, the timing can be extremely important, so doing things in composition might be too late.
4 Views