HarmonyOS Tabs?

tabs组件使用 SubTabBarStyle tabBar的字体颜色还有tabBar的颜色在哪里设置

阅读 479
1 个回答

设置字体颜色,可以使用自定义导航栏参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-navigation-tabs-V5\#自定义导航栏

demo:

@Entry
@Component
struct TabsExample1 {
  @State currentIndex: number = 2

  @Builder tabBuilder(title: string, targetIndex: number) {
    Column() {
      Text(title)
        .fontColor(this.currentIndex === targetIndex ? '#FF0000' : '#00FF00')
    }
  }

  build() {
    Column() {
      Tabs({ barPosition: BarPosition.End }) {
        TabContent() {

        }.tabBar(this.tabBuilder('首页', 0))

        TabContent() {

        }.tabBar(this.tabBuilder('发现', 1))

        TabContent() {

        }.tabBar(this.tabBuilder('推荐', 2))

        TabContent() {

        }.tabBar(this.tabBuilder('我的', 3))
      }
      .animationDuration(0)
      .backgroundColor('#F1F3F5')
      .onChange((index: number) => {
        this.currentIndex = index
      })
    }.width('100%')
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进