HarmonyOS SubTabBarStyle组件如何定制选中文本的颜色

HarmonyOS
2024-12-26 13:54:25
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
put_get

可以通过自定义导航栏,判断当前的currentIndex和targetIndex是否相等判断是否选中,然后给选中的tab设置选中颜色。

@Builder tabBuilder(title: string, targetIndex: number, selectedImg: Resource, normalImg: Resource) {
  Column() {
    Image(this.currentIndex === targetIndex ? selectedImg : normalImg)
      .size({ width: 25, height: 25 })
    Text(title)
      .fontColor(this.currentIndex === targetIndex ? '#1698CE' : '#6B6B6B')
  }
  .width('100%')
  .height(50)
  .justifyContent(FlexAlign.Center)
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.

参考官方API链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-navigation-tabs-V5#自定义导航栏

分享
微博
QQ
微信
回复
2024-12-26 16:43:11
相关问题
如果改变 SubTabBarStyle 字体颜色
1340浏览 • 1回复 待解决
HarmonyOS AVCastPicker组件定制问题
639浏览 • 1回复 待解决
HarmonyOS Badge文本颜色设置不生效
1063浏览 • 1回复 待解决
如何获取Text组件中文宽度
3130浏览 • 1回复 待解决