I wanted to know how we can add multiple modifier, for example adding background, padding and more to an android jetpack composable?
Asked
Active
Viewed 4,824 times
2 Answers
23
It's really simple; You can chain multiple modifiers.
Column(modifier = Modifier.preferredHeight(500.dp).padding(100.dp)) {
Text("Hello") }
And The order is important; Modifier elements to the left are applied before modifier elements to the right.

Parisa Baastani
- 1,713
- 14
- 31
-
1How can I chain `fillMaxSize` with `padding`? – IgorGanapolsky Jan 08 '23 at 14:23
-
2@IgorGanapolsky Column(modifier = Modifier.padding(24.dp).fillMaxWidth()) { Text(text = "hello") Text(text = name) } – Ashton Feb 01 '23 at 09:13
0
if you have to use two different modifier, you can simply use .then() function to add second modifier
For Example, let's say you have a composable function in which we have passed a modifier as a parameter and inside that function we have a box which already have a modifier. so by using then modifier you can add the modifier which have been passed as a parameter
@Composable
fun myView(modifier: Modifier) {
Box(
modifier = Modifier
.padding(8.dp)
.background(Color.Black)
.then(modifier)
)
}
and yes order your in which you are adding modifiers matters

Aditya Sharma
- 1
- 1