How to change primaryVariant color in compose theme?

Viewed 428

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

1 Answers

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>
Related