我想修改每一个Tab
的宽度,但是我做不到,我知道可以定制,但是我就是想修改宽度,有没有办法?
@OptIn(ExperimentalPagerApi::class)
@Preview
@Composable
fun TabPreviewTest() {
val scope = rememberCoroutineScope()
val colorScheme = MaterialTheme.colorScheme
val pagerState = rememberPagerState(initialPage = 1)
val titleList = rememberSaveable { mutableListOf("关注", "推荐", "美食", "护肤", "穿搭", "健身塑形", "数码") }
ScrollableTabRow(
selectedTabIndex = pagerState.currentPage,
containerColor = colorScheme.surface.copy(0.94f),
contentColor = colorScheme.primary,
divider = { DividerView(start = 0) }) {
titleList.forEachIndexed { index, title ->
Tab(text = { Text(text = title) },
selected = pagerState.currentPage == index,
selectedContentColor = colorScheme.primary,
unselectedContentColor = colorScheme.gray,
onClick = {
scope.launch { pagerState.scrollToPage(index) }
//onClick(index)
},
modifier = Modifier.padding(0.dp).width(0.dp)
)
}
}
}
1条答案
按热度按时间nkoocmlb1#
当Tab宽度大于90.dp时,您可以更改它,因为在源代码中,它是使用最小值为90.dp的Cosntraints测量的
在子合成版面中
如果复制粘贴源代码并将minimumTabWidth更改为0,则可以指定任何宽度修饰符