Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to Set Button Height and Width in Jetpack Compose?

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading