https://kotlinlang.org logo
#compose
Title
# compose
g

Gaurav

07/04/2021, 11:24 AM
Hey..I just started learning compose...how can we set color in spacer.....I want to have a 30 dp space with white color....by default it is coming black color....it tried setting spacer.background(white) but not working....suggest any way to do so...thanx
Or we can do it without using spacer...like in XML we had view which just leave desired space..... something like that in compose?
f

Foso

07/04/2021, 11:33 AM
This should work:
Copy code
Spacer(modifier = Modifier
    .size(30.dp)
    .background(Color.White))
1
g

Gaurav

07/04/2021, 11:45 AM
Yess @Foso it worked...thanx😊 I made a mistake i.e
Copy code
modifier.background(white).
height(30.dp).fillmaxheight()
...while I should have done
fillmaxwidth....
due to this color was not coming....these little mistakes😅😅
👍 1
f

Filip Wiesner

07/04/2021, 6:08 PM
Shouldn't Space be transparent by default? I think that if you want background, you should use Box instead.
👍 1