Search code examples
androidbackgroundandroid-jetpack-compose

How to use both color and image as background with Jetpack Compose?


I want to use a background color (say blue) for my screen, and an image (to add effect) too in addition to color. How do I do it?

Currently I'm doing:

Box(
    modifier = Modifier
        .fillMaxSize()
        .background(color = MaterialTheme.colors.background)
) {
    // ...
}

But in background there is no option to specify an image. How do I do this?


Solution

  • Box(modifier = Modifier.fillMaxSize().background(color = MaterialTheme.colors.background)) {
      Image(
          painter = painterResource(R.drawable.header),
          contentDescription = null,
          modifier = Modifier
               .fillMaxSize(),
          contentScale = // Your contentscale
      )
    }