0

How to set button height and width in Jetpack Compose? I can't set button height and width.

Button(onClick = {  },
       modifier =  Modifier.size(width = 80.dp,height = 80.dp)
        ) {
        Text(text = "Lorem")
    }

The button takes up the entire screen.The button takes up the entire screen

Jorpy
  • 55
  • 1
  • 6

1 Answers1

1

You have to use Column, Row or any other layout. Read more about in here about Layouts. Basic Layouts comes from here.

@Preview(showBackground = true)
@Composable
fun ButtonView() {
    Column(modifier = Modifier.fillMaxSize().background(Color.Yellow)) {
        Button(
            onClick = { },
            modifier = Modifier.size(width = 80.dp, height = 80.dp)
        ) {
            Text(text = "Lorem")
        }
    }
}

Output

enter image description here

Kotlin Learner
  • 3,995
  • 6
  • 47
  • 127