简体   繁体   中英

Align text to right in button in Jetpack compose

I have button with text:

Button(
                colors = ButtonDefaults.buttonColors(
                    backgroundColor = Color.Transparent,
                    contentColor = colors.primary,
                ),
                elevation = null,
                onClick = {},
                border = BorderStroke(0.dp, Color.Transparent),
            ) {
                Text(
                    text = stringResource(id = R.string.name),
                    fontSize = 12.sp,
                    textAlign = TextAlign.Right
                )
            }

Now text in button is centered. How can I move this text to right/end in this button. textAlign = TextAlign.Right not working.

You have to specify width for Button and Text .

Button(
    colors = ButtonDefaults.buttonColors(
        backgroundColor = Color.Transparent,
        contentColor = colors.primary,
    ),
    elevation = null,
    onClick = {},
    border = BorderStroke(0.dp, Color.Transparent),
    modifier = Modifier.fillMaxWidth()
) {
    Text(
        text = stringResource(id = R.string.name),
        fontSize = 12.sp,
        textAlign = TextAlign.Right,
        modifier = Modifier.fillMaxWidth(),
    )
}

I have given full width for Button

modifier = Modifier.fillMaxWidth()

Also let your Text to occupy that parent width .

modifier = Modifier.fillMaxWidth()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM