11

I wanted to know how we can add multiple modifier, for example adding background, padding and more to an android jetpack composable?

Parisa Baastani
  • 1,713
  • 14
  • 31

2 Answers2

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
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