Is there a way to use `MaterialTheme.colors.prima...
# compose
s
Is there a way to use
MaterialTheme.colors.primarySurface
in an Activity …when i try to use it example:
Copy code
systemUiController.setNavigationBarColor(color = MaterialTheme.colors.primarySurface)
i get the error @Composable invocations can only happen from the context of a @Composable function
k
You have to make this call inside a Compose context, what you're trying to do is similar to trying to call a
suspend
function from a non-suspend one. Pass the
systemUiController
down to your composable and then use a
SideEffect
: https://developer.android.com/jetpack/compose/side-effects#sideeffect-publish
a
There's a system UI controller accompanist library to set navigation bar color from compose code. https://google.github.io/accompanist/systemuicontroller/
m
Also, what i've done here is to create another wrapper function for my theme which, in addition to setting up the theme colors, typography, etc... also sets the system bar color using the above mentioned library.