[英]How to update TabRow Indicator with LazyListState in jetpack compose?
由于公司政策,我无法显示该应用程序,但几乎我有一个惰性列表,它会在选择选项卡时设置动画,但当用户在惰性列表上滚动时,选项卡指示器也需要根据更新到用户所在的相应部分和选项卡。 我让文本颜色在滚动时更新,但不确定如何更新指示器? 似乎该指标仅在重组时启动。
@Composable
private fun MyTab(
tabs: List<MyTabs>,
lazyListState: LazyListState
){
var selectedIndex by remember { mutableStateOf(0) }
val scope = rememberCoroutineScope()
TabRow(
selectedTabIndex = selectedIndex,
indicator = { tabPositions ->
TabRowDefaults.Indicator(
modifier = Modifier.tabIndicatorOffset(tabPositions[selectedIndex])
)
}
){
tabs.forEachIndexed { index, item ->
val selected = (selectedIndex == index)
Tab(
selected = selected,
onClick = {
selectedIndex = index
scope.launch{
lazyListState.animateScrollToItem(selectedIndex)
}
},
text = {
Text(color = if(lazyListState.firstVisibleItemIndex == index) white else red
}
)
}
}
}
哇,我刚刚解决了。
只需设置 tabPositions[lazyListState.firstVisibleItemIndex]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.