https://kotlinlang.org logo
#compose
Title
# compose
s

ShreemanArjun

04/23/2020, 7:39 PM
How to place a Text in center in latest update dev 09 version? There is no composable function Center(deprecated). Please help if anyone can...
🎉 1
z

Zach Klippenstein (he/him) [MOD]

04/23/2020, 7:46 PM
You need to use a modifier:
Text(…, modifier = Modifier.wrapContentSize(Alignment.Center))
a

alexzhukovich

04/23/2020, 7:46 PM
You can try
Copy code
Box(gravity = ContentGravity.Center) {
    Text(...)
}
Yes, in case Text better to use modifier, but in case of multiple
@Composable
function you can use Box
s

ShreemanArjun

04/23/2020, 7:57 PM
still showing un top left
@alexzhukovich @Zach Klippenstein (he/him) [MOD] still showing top left of display
i want to show it on the center of display as Center is deprecated in latest version.
l

Leland Richardson [G]

04/23/2020, 8:00 PM
you probably also want
Modifier.fillMaxWidth()
or something similar so that it is centering across the full width that you are wanting
a

alexzhukovich

04/23/2020, 8:02 PM
The following code is working for me:
Copy code
Text(
    text = "abc",
    modifier = Modifier.fillMaxWidth() + Modifier.wrapContentSize(Alignment.Center)
)
s

ShreemanArjun

04/23/2020, 8:07 PM
@alexzhukovich are you using latest dev09 version?
a

alexzhukovich

04/23/2020, 8:09 PM
yes
Could you share your code?
s

ShreemanArjun

04/23/2020, 8:11 PM
hey i found the solution: Text(modifier=Modifier. fillMaxSize() +Modifier. wrapContentSize(Alignment. Center))
@alexzhukovich Thanks for help.
a

Adam Powell

04/23/2020, 9:42 PM
Just
Modifier.fillMaxSize().wrapContentSize(Alignment.Center)
, it's cleaner 🙂
but yes, the above is identical to the behavior of the old
Center
composable wrapper
3 Views