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

Left Aligning Button Text in Jetpack Compose

I am using the following code to create an OutlinedButton in Jetpack Compose:

OutlinedButton(
            colors = ButtonDefaults.outlinedButtonColors(Color.Transparent),
            border = BorderStroke(0.dp, Color.Transparent),
            modifier = Modifier.fillMaxWidth()
                               .background(
                color = Color.Transparent,
        shape = RectangleShape, // Oval shape

        //border = androidx.compose.ui.drawBorder(2.dp, Color.Red) // Border color and width
        ),
            onClick = {}
        ) {

            Text(
                modifier = Modifier.padding(horizontal = 0.dp, vertical = 0.dp),
                color = Color.Black,
                text = text,
                textAlign = TextAlign.Left,
                fontSize = 15.sp,
            )
        }

I tried using TextAlign.Left and TextAlign.Start. However, it always aligns in the center:

enter image description here

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

How to solve this?

>Solution :

Add Row inside Button

OutlinedButton(onClick = {  }, modifier = Modifier
        .fillMaxWidth()
        .height(48.dp)) {

        Row(modifier = Modifier.fillMaxWidth()) {
            Text(text = "Button Text", textAlign = TextAlign.Start)

        }


    }
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