2

I am trying to learn how to set a custom application theme in Jetpack compose but I am struggling to set color of primaryVariant color that doesn't seem to be overridden when I create my custom color pallet.

  private val MyLightColorPalette = lightColors(
    primary = Green,
    primaryVariant = Grey,
    onPrimary = Color.White,
    secondary = Green,
    secondaryVariant = Grey,
    onSecondary = Color.White,
    error = DarkGrey,
)

enter image description here

This is my color pallet and yet it uses that purple color instead of green. Does somebody know why it still using the default purple color?

Here is the rest of the code:

@Composable
fun MyAppTheme(darkTheme: Boolean = isSystemInDarkTheme(), content: @Composable () -> Unit) {
    val colors = if (darkTheme) {
        MyDarkColorPalette
    } else {
        MyLightColorPalette
    }
    MaterialTheme(
            colors = colors,
            typography = Typography,
            shapes = Shapes,
            content = content
    )
}

@AndroidEntryPoint
class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MyAppTheme {
                Scaffold() {
                    TopBar()
                }
            }
        }
    }
}

Compose version that I am using is 1.0.4

clamentjohn
  • 3,417
  • 2
  • 18
  • 42
Pesa
  • 241
  • 1
  • 3
  • 8
  • 1
    Does this answer your question? [how to change statusbar color in jetpack compose?](https://stackoverflow.com/questions/65610216/how-to-change-statusbar-color-in-jetpack-compose) – Phil Dukhov Oct 19 '21 at 08:56
  • Yeah it does the job, thank you :) but its strange that another library must be used for it – Pesa Oct 19 '21 at 10:36

1 Answers1

3

If the requirement is just to change the status bar color throughout the app to a solid color, this would also work without Accompanist.

Add this to your activity theme XML code.

<item name="android:statusBarColor" tools:targetApi="l">@color/status_bar</item>
Abhimanyu
  • 11,351
  • 7
  • 51
  • 121