2

I want to make a circle-shaped text that will fill all the available on the screen but still remain a circle. This is the code I've written for the component.

    Box(modifier = modifier
        .padding(4.dp)
        .fillMaxSize()
        .clip(CircleShape),
        contentAlignment = Alignment.Center
    ) {
        Text(text = "hello", modifier = Modifier.fillMaxSize().background(Color.Yellow))
}

And this is not the result I want it to be. Any ideas on how I can achieve this?

enter image description here

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
Maryam Mirzaie
  • 536
  • 6
  • 24

1 Answers1

6

You can apply the aspectRatio(1f) modifier to have height = width in the Box.

Something like:

Box(modifier = Modifier
    .padding(4.dp)
    .fillMaxSize()
    .aspectRatio(1f)
    .background(Color.Blue, shape = CircleShape),
    contentAlignment = Alignment.Center
) {
    Text(text = "hello", color= Yellow,   textAlign = TextAlign.Center)
}

enter image description here

If you want to have a better control of the Text composable you can also check this question.

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841