PhongBM
PhongBM

Reputation: 938

Compose - Custom MaterialTheme colors not working?

I want to custom colors system using Compose, but it isn't working. It effected by colors in themes.xml.

Activity

class DemoComposeMainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContent {
            val colorPrimary = colorResource(R.color.md_green_500)
            val colorSecondary = colorResource(R.color.md_orange_500)

            val colors = lightColors(
                    primary = colorPrimary,
                    primaryVariant = colorPrimary,
                    onPrimary = Color.White,
                    secondary = colorSecondary,
                    secondaryVariant = colorSecondary,
                    onSecondary = Color.White)

            MaterialTheme(colors = colors) {
                // TODO
            }
        }
    }

}

Please help me. Thanks.

image

Upvotes: 0

Views: 2499

Answers (1)

Gabriele Mariotti
Gabriele Mariotti

Reputation: 363459

The statusbar color is based on the android:statusBarColor defined in your app theme.
If you want to change the statusBar color you can use the accompanist library.

Something like.

        val systemUiController = rememberSystemUiController()
        val useDarkIcons = MaterialTheme.colors.isLight

        SideEffect {
            systemUiController.setSystemBarsColor(
                color = Color.Transparent,
                darkIcons = useDarkIcons
            )

            // setStatusBarsColor() and setNavigationBarsColor() also exist
        }

Upvotes: 2

Related Questions