Android Jetpack Compose TabRow Tab自定义选中下划线颜色和删除未选中的灰色的下划线

项目需求需要,百度了很多,资料比较少,最后也尝试摸索下了,最终实现了想要的效果。

上图:

 上代码:(一些变量复制报错需要自己定义,如:selectedTabIndex 和颜色)

TabRow(
            selectedTabIndex = currentTabIndex.value,
            backgroundColor = Color.White,
            //删除未选中显示的灰色下划线
            divider = {},
            indicator = { tabPositions ->
                TabRowDefaults.Indicator(
                    //使用系统默认的
                    modifier = Modifier.tabIndicatorOffset(tabPositions[currentTabIndex.value]),
                    //选中下划线的颜色
                    color = RedColor
                )
            },
        ) {
            tabList.forEachIndexed { index, s ->
                Tab(text = {
                    Text(
                        text = s,
                        fontSize = 18.sp,
                        fontWeight = if (currentTabIndex.value == index) FontWeight.Bold else null,
                        color = if (currentTabIndex.value == index) RedColor else Color.Black
                    )
                }, selected = currentTabIndex.value == index, onClick = {
                    currentTabIndex.value = index
                }, selectedContentColor = RedColor
                )
            }
        }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值