1# TabTitleBar
2
3
4页签型标题栏,用于页面之间的切换。仅一级页面适用。
5
6
7> **说明:**
8>
9> 该组件从API Version 10开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
10
11
12## 导入模块
13
14```
15import { TabTitleBar } from '@kit.ArkUI'
16```
17
18
19## 子组件
20
2122
23## 属性
24不支持[通用属性](ts-universal-attributes-size.md)
25
26
27## TabTitleBar
28
29TabTitleBar({tabItems: Array<TabTitleBarTabItem>, menuItems?: Array<TabTitleBarMenuItem>, swiperContent: () => void})
30
31**装饰器类型:**\@Component
32
33**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
34
35**系统能力:** SystemCapability.ArkUI.ArkUI.Full
36
37**参数:**
38
39| 名称 | 类型 | 必填 | 装饰器类型 | 说明 |
40| -------- | -------- | -------- | -------- | -------- |
41| tabItems | Array<[TabTitleBarTabItem](#tabtitlebartabitem)> | 是 | - | 左侧页签项目列表,定义标题栏左侧的页签项目。 |
42| menuItems | Array<[TabTitleBarMenuItem](#tabtitlebarmenuitem)> | 否 | - | 右侧菜单项目列表,定义标题栏右侧的菜单项目。 |
43| swiperContent | () => void | 是 | \@BuilderParam | 页签列表关联的页面内容构造器。 |
44
45> **说明:**
46> 
47> 入参对象不可为undefined,即`TabTitleBar(undefined)`。
48
49## TabTitleBarMenuItem
50
51**系统能力:** SystemCapability.ArkUI.ArkUI.Full
52
53| 名称 | 类型 | 必填 | 说明 |
54| -------- | -------- | -------- | -------- |
55| value | [ResourceStr](ts-types.md#resourcestr) | 是 | 图标资源。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
56| label<sup>13+</sup> | [ResourceStr](ts-types.md#resourcestr) | 否 | 图标标签描述。<br/>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 |
57| isEnabled | boolean | 否 | 是否启用。默认启用。true:启用,false:禁用。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
58| action | ()&nbsp;=&gt;&nbsp;void | 否 | 触发时的动作闭包。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
59
60## TabTitleBarTabItem
61
62**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
63
64**系统能力:** SystemCapability.ArkUI.ArkUI.Full
65
66| 名称 | 类型 | 必填 | 说明 |
67| -------- | -------- | -------- | -------- |
68| title | [ResourceStr](ts-types.md#resourcestr) | 是 | 文字页签。 |
69| icon | [ResourceStr](ts-types.md#resourcestr) | 否 | 图片页签资源。 |
70
71
72## 事件
73不支持[通用事件](ts-universal-events-click.md)
74
75## 示例
76
77```ts
78import { TabTitleBar, promptAction } from '@kit.ArkUI'
79
80class tabItem {
81  title: ResourceStr;
82  icon?: ResourceStr;
83  constructor(title: ResourceStr,icon?: ResourceStr) {
84    this.title = title
85    this.icon = icon
86  }
87}
88
89interface menuItem {
90  value: ResourceStr;
91  isEnabled?: boolean;
92  action?: () => void
93}
94
95@Entry
96@Component
97struct Index {
98  @Builder
99  componentBuilder() {
100    Text("#1ABC9C\nTURQUOISE")
101      .fontWeight(FontWeight.Bold)
102      .fontSize(14)
103      .width("100%")
104      .textAlign(TextAlign.Center)
105      .fontColor("#CCFFFFFF")
106      .backgroundColor("#1ABC9C")
107    Text("#16A085\nGREEN SEA")
108      .fontWeight(FontWeight.Bold)
109      .fontSize(14)
110      .width("100%")
111      .textAlign(TextAlign.Center)
112      .fontColor("#CCFFFFFF")
113      .backgroundColor("#16A085")
114    Text("#2ECC71\nEMERALD")
115      .fontWeight(FontWeight.Bold)
116      .fontSize(14)
117      .width("100%")
118      .textAlign(TextAlign.Center)
119      .fontColor("#CCFFFFFF")
120      .backgroundColor("#2ECC71")
121    Text("#27AE60\nNEPHRITIS")
122      .fontWeight(FontWeight.Bold)
123      .fontSize(14)
124      .width("100%")
125      .textAlign(TextAlign.Center)
126      .fontColor("#CCFFFFFF")
127      .backgroundColor("#27AE60")
128    Text("#3498DB\nPETER RIVER")
129      .fontWeight(FontWeight.Bold)
130      .fontSize(14)
131      .width("100%")
132      .textAlign(TextAlign.Center)
133      .fontColor("#CCFFFFFF")
134      .backgroundColor("#3498DB")
135  }
136
137  private readonly tabItems: Array<tabItem> = [new tabItem('页签1'),new tabItem('页签2'),new tabItem('页签3'),new tabItem("Happy",$r('app.media.emoji_happy')),new tabItem('页签4')]
138  private  readonly menuItems: Array<menuItem> = [
139    {
140      value: $r('app.media.ic_public_reduce'),
141      isEnabled: true,
142      action: () => promptAction.showToast({ message: "on item click! index 0" })
143    },
144    {
145      value: $r('app.media.ic_public_edit'),
146      isEnabled: true,
147      action: () => promptAction.showToast({ message: "on item click! index 1" })
148    },
149    {
150      value: $r('app.media.ic_public_save'),
151      isEnabled: true,
152      action: () => promptAction.showToast({ message: "on item click! index 2" })
153    },
154  ]
155
156  build() {
157    Row() {
158      Column() {
159        TabTitleBar({
160          swiperContent: this.componentBuilder,
161          tabItems: this.tabItems,
162          menuItems: this.menuItems,
163        })
164      }.width('100%')
165    }.height('100%')
166  }
167}
168```
169
170![zh-cn_image_0000001616916278](figures/zh-cn_image_0000001616916278.png)
171