可参考示例:const tabList: Array<string> = ["综合", "产品", "资讯", "价格"]; @Entry @Component struct Index9{ private tabController: TabsController = new TabsController(); @State currentIndex: number = 0; scroller: Scroller = new Scroller() build() { Tabs({ barPosition: BarPosition.Start, index: this.currentIndex, controller: this.tabController }) { TabContent() { Column(){ Scroll(this.scroller){ Row(){ Text("全部") .fontSize(14) .padding({ left: 10, right: 10, top: 5, bottom: 5 }) .borderRadius(3) .onClick(() => { }) Text("最近一周") .fontSize(14) .padding({ left: 10, right: 10, top: 5, bottom: 5 }) .borderRadius(3) .onClick(() => { }) Text("最近30天") .fontSize(14) .padding({ left: 10, right: 10, top: 5, bottom: 5 }) .borderRadius(3) .onClick(() => { }) Text("最近半年") .fontSize(14) .padding({ left: 10, right: 10, top: 5, bottom: 5 }) .borderRadius(3) .onClick(() => { }) Text("自选时间") .fontSize(14) .padding({ left: 10, right: 10, top: 5, bottom: 5 }) .borderRadius(3) .onClick(() => { }) Row(){ Text("开始时间") .fontSize(14) .padding({ left: 10, right: 10, top: 5, bottom: 5 }) .onClick(() => { }) Divider() .strokeWidth(0.5) .width(7) .margin({left: 3, right: 3}) Text("结束时间") .fontSize(14) .padding({ left: 10, right: 10, top: 5, bottom: 5 }) .onClick(() => { }) } .alignItems(VerticalAlign.Center) .margin({left: 15, right: 15}) } .margin({top: 10, bottom: 10, left: 20, right: 20}) } .scrollBar(BarState.Off) .scrollable(ScrollDirection.Horizontal) .edgeEffect(EdgeEffect.Spring) Text("第一页") } .width("100%") .height("100%") } .tabBar(this.tabBuilder(0, tabList[0])) TabContent() { } .tabBar(this.tabBuilder(1, tabList[1])) TabContent() { } .tabBar(this.tabBuilder(2, tabList[2])) TabContent() { } .tabBar(this.tabBuilder(3, tabList[3])) } .width("100%") .height("100%") .barMode(BarMode.Fixed) .onChange((index: number) => { this.currentIndex = index; }) } @Builder tabBuilder(index: number, name: string) { Column() { Text(name) .fontColor("#121212") .fontSize(16) Column() .width(25) .height(4) .borderRadius(2) .linearGradient({ direction: GradientDirection.Right, // 渐变方向 repeating: false, // 渐变颜色是否重复 colors: [[0xFF8800, 0.0], [0xD23023, 1]] // 数组末尾元素占比小于1时满足重复着色效果 }) .opacity(this.currentIndex === index ? 1 : 0) .margin({top: 7}) Divider() .strokeWidth(0.5) .width("100%") .color("#F2F2F2") } .width("100%") } }
可参考示例: