https://kotlinlang.org logo
Title
a

Alvin Dizon

05/25/2023, 7:16 AM
How do I center the text inside a
FilterChip
? I have something like this:
Row(
        modifier = modifier.fillMaxWidth(),
        verticalAlignment = <http://Alignment.Top|Alignment.Top>,
        horizontalArrangement = Arrangement.SpaceEvenly
    ) {
        filters.fastForEachIndexed { index, filter ->
            FilterChip(
                modifier = when (filter) {
                    FeedFilters.Feed -> Modifier.padding(start = 16.dp)
                    FeedFilters.MyPosts -> Modifier.padding(horizontal = 10.dp)
                    FeedFilters.OffersSent -> Modifier.padding(end = 16.dp)
                }.weight(1f),
                label = {
                    ProvideTextStyle(value = CommunityTheme.typography.button1) {
                        Text(
                            fontWeight = if (selectedIndex == index) FontWeight.Bold else FontWeight.Normal,
                            text = stringResource(id = filter.labelRes),
                            textAlign = TextAlign.Center
                        )
                    }
                }
            )
        }
    }
My row currently looks like this:
So I applied
Modifier.align(Alignment.CenterVertically).fillMaxWidth()
to the
Text
and it kind of centered the String, but there's way too much space to the left of the String:
Looking at
ChipContent
, there's additional padding to the left of the
label
, I might just have to roll my own implementation