How do I remove undeline of TabRow in Jetpack Compose?

3.3k Views Asked by At

I am tiring to remove the underline of TabRow, but did not succeed. Here is the code:

@ExperimentalPagerApi
@Composable
fun Tabs(pagerState: PagerState) {
    val tabs = listOf(R.string.add, R.string.add)
    val scope = rememberCoroutineScope()
    val currentPage = pagerState.currentPage
    TabRow(
        modifier = Modifier
            .padding(start = 36.dp, top = 16.dp, end = 36.dp)
            .clip(shape = RoundedCornerShape(16.dp)),
        selectedTabIndex = currentPage,
        backgroundColor = Color.Transparent,
        tabs = {
            tabs.forEachIndexed { index, tab ->
                Tab(
                    modifier = Modifier.clip(RoundedCornerShape(16.dp)),
                    text = {
                        Text(text = stringResource(id = tab))
                    },
                    selected = currentPage == index,
                    onClick = {
                        scope.launch {
                            pagerState.animateScrollToPage(index)
                        }
                    }
                )
            }
        }
    )
}

enter image description here

I only want to have the selected color.

3

There are 3 best solutions below

1
Thracian On BEST ANSWER

set divider param of TabRow as divider={}. Default one is

divider: @Composable () -> Unit = @Composable {
    Divider()
}
0
Brian Roper On

The divider answer no no longer works if you upgrade to material 3. Changing the indicator the same way worked for me.

TabRow(
       selectedTabIndex = selectedTab.ordinal,
       containerColor = Color.White,
       indicator = {

       }
) { }
0
Felix Kariuki On

When using a Scrollable tabRow in material 3 you can remove the underline below the entire scrollable tab row and the indicator for individual selected tabs like this

ScrollableTabRow(
        selectedTabIndex = tabIndex, edgePadding = 16.dp,
        indicator = {

        }, divider = {

        }
    ) { }

removing the tab indicator only

ScrollableTabRow(
        selectedTabIndex = tabIndex, edgePadding = 16.dp,
        indicator = {

        }
    ) { }

and to remove the underline below the entire scrollable tab row

ScrollableTabRow(
        selectedTabIndex = tabIndex, edgePadding = 16.dp,
        divider = {

        }
    ) { }