How can I set a `Drawable` as a background of a mo...
# compose
p
How can I set a
Drawable
as a background of a modifier in compose? In java, it was done like this:
layout.setBackground(bg.getDrawable());
a
use a Box, then place an image in that box, then overlay the image with your desired UI
☝🏼 1
p
well, it's a bit more complicated, It's a LazyColumn, and it haves some items. Ok, I need the drawable to be the background of the LazyColumn
so, how can I do that using a Box? I suppose you mean placing a Image inside the Box, but the drawable must be the exact size of the LazyColumn, so I don't know how to do that, can you help me?
@andylamax maybe using onGloballyPositioned ? it seems to be a very rude way, I hope you know a correct way
a
Does't this snippet work?
Copy code
@Composable
fun ComponentWithBackGround() {
  Box(modifier = Modifier.fillMaxSize()) {
    Image(..., modifier.fillMaxSize())
    LazyColumn(modifier = Modifier.fillMaxSize()) {
      // you code goes here
    }
  }
}
p
well, maybe I didn't explain myself correctly, I don't wanna have the drawable filling the entire height of the screen
if the lazycolumn has only 2 or 3 items, will have only a portion of the height of the screen
so @andylamax the drawable should be the same size, not the entire screen height