• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# TabTitleBar
2<!--Kit: ArkUI-->
3<!--Subsystem: ArkUI-->
4<!--Owner: @fengluochenai-->
5<!--Designer: @YanSanzo-->
6<!--Tester: @tinygreyy-->
7<!--Adviser: @HelloCrease-->
8
9
10页签型标题栏,用于页面之间的切换。仅一级页面适用。
11
12
13> **说明:**
14>
15> 该组件从API version 10开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
16>
17
18
19## 导入模块
20
21```
22import { TabTitleBar } from '@kit.ArkUI';
23```
24
25
26## 子组件
27
2829
30## 属性
31不支持[通用属性](ts-component-general-attributes.md)。
32
33
34## TabTitleBar
35
36TabTitleBar({tabItems: Array&lt;TabTitleBarTabItem&gt;, menuItems?: Array&lt;TabTitleBarMenuItem&gt;, swiperContent: () =&gt; void})
37
38**装饰器类型:**\@Component
39
40**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
41
42**系统能力:** SystemCapability.ArkUI.ArkUI.Full
43
44**设备行为差异:** 该接口在Wearable设备上使用时,应用程序运行异常, 异常信息中提示接口未定义,在其他设备中可正常调用。
45
46| 名称 | 类型 | 必填 | 装饰器类型 | 说明 |
47| -------- | -------- | -------- | -------- | -------- |
48| tabItems | Array&lt;[TabTitleBarTabItem](#tabtitlebartabitem)&gt; | 是 | - | 左侧页签项目列表,定义标题栏左侧的页签项目。 |
49| menuItems | Array&lt;[TabTitleBarMenuItem](#tabtitlebarmenuitem)&gt; | 否 | - | 右侧菜单项目列表,定义标题栏右侧的菜单项目。 |
50| swiperContent | ()&nbsp;=&gt;&nbsp;void | 是 | \@BuilderParam | 页签列表关联的页面内容构造器。 |
51
52> **说明:**
53>
54> 入参对象不可为undefined,即`TabTitleBar(undefined)`。
55
56## TabTitleBarMenuItem
57
58**系统能力:** SystemCapability.ArkUI.ArkUI.Full
59
60**设备行为差异:** 该接口在Wearable设备上使用时,应用程序运行异常, 异常信息中提示接口未定义,在其他设备中可正常调用。
61
62| 名称 | 类型 | 必填 | 说明 |
63| -------- | -------- | -------- | -------- |
64| value | [ResourceStr](ts-types.md#resourcestr) | 是 | 图标资源。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
65| symbolStyle<sup>18+</sup> | [SymbolGlyphModifier](ts-universal-attributes-attribute-symbolglyphmodifier.md#symbolglyphmodifier) | 否 | Symbol图标资源,优先级大于value。<br/>**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。 |
66| label<sup>13+</sup> | [ResourceStr](ts-types.md#resourcestr) | 否 | 图标标签描述。<br/>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 |
67| isEnabled | boolean | 否 | 是否启用。默认禁用。true:启用,false:禁用。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
68| action | ()&nbsp;=&gt;&nbsp;void | 否 | 触发时的动作闭包。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
69| accessibilityLevel<sup>18+<sup>       | string  | 否 | 标题栏右侧自定义按钮无障碍重要性。用于控制当前项是否可被无障碍辅助服务所识别。<br/>支持的值为:<br/>"auto":当前组件会转换'yes'。<br/>"yes":当前组件可被无障碍辅助服务所识别。<br/>"no":当前组件不可被无障碍辅助服务所识别。<br/>"no-hide-descendants":当前组件及其所有子组件不可被无障碍辅助服务所识别。<br/>默认值:"auto"。<br/>**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。 |
70| accessibilityText<sup>18+<sup>        | [ResourceStr](ts-types.md#resourcestr) | 否 | 标题栏右侧自定义按钮的无障碍文本属性。当组件不包含文本属性时,屏幕朗读选中此组件时不播报,使用者无法清楚地知道当前选中了什么组件。为了解决此场景,开发人员可为不包含文字信息的组件设置无障碍文本,当屏幕朗读选中此组件时播报无障碍文本的内容,帮助屏幕朗读的使用者清楚地知道自己选中了什么组件。<br/>默认值:有label默认值为当前项label属性内容,没有设置label时,默认值为“ ”。<br/>**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。                                     |
71| accessibilityDescription<sup>18+<sup> | [ResourceStr](ts-types.md#resourcestr) | 否 | 标题栏右侧自定义按钮的无障碍描述。此描述用于向用户详细解释当前组件,开发人员应为组件的这一属性提供较为详尽的文本说明,以协助用户理解即将执行的操作及其可能产生的后果。特别是当这些后果无法仅从组件的属性和无障碍文本中直接获知时。如果组件同时具备文本属性和无障碍说明属性,当组件被选中时,系统将首先播报组件的文本属性,随后播报无障碍说明属性的内容。<br/>默认值为“单指双击即可执行”。<br/>**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。           |
72
73## TabTitleBarTabItem
74
75**系统能力:** SystemCapability.ArkUI.ArkUI.Full
76
77**设备行为差异:** 该接口在Wearable设备上使用时,应用程序运行异常, 异常信息中提示接口未定义,在其他设备中可正常调用。
78
79| 名称 | 类型 | 必填 | 说明 |
80| -------- | -------- | -------- | -------- |
81| title | [ResourceStr](ts-types.md#resourcestr) | 是 | 文字页签。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
82| icon | [ResourceStr](ts-types.md#resourcestr) | 否 | 图片页签资源。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
83| symbolStyle<sup>18+</sup> | [SymbolGlyphModifier](ts-universal-attributes-attribute-symbolglyphmodifier.md#symbolglyphmodifier) | 否 | Symbol图片页签资源,优先级大于icon。<br/>**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。 |
84
85
86## 事件
87不支持[通用事件](ts-component-general-events.md)。
88
89## 示例
90
91### 示例1(简单的页签型标题栏)
92该示例实现了带有左侧页签和右侧菜单列表的页签型标题栏。
93```ts
94import { TabTitleBar, Prompt, TabTitleBarTabItem, TabTitleBarMenuItem } from '@kit.ArkUI';
95
96@Entry
97@Component
98struct Index {
99  @Builder
100  //定义页签列表关联的页面
101  componentBuilder() {
102    Text("#1ABC9C\nTURQUOISE")
103      .fontWeight(FontWeight.Bold)
104      .fontSize(14)
105      .width("100%")
106      .textAlign(TextAlign.Center)
107      .fontColor("#CCFFFFFF")
108      .backgroundColor("#1ABC9C")
109    Text("#16A085\nGREEN SEA")
110      .fontWeight(FontWeight.Bold)
111      .fontSize(14)
112      .width("100%")
113      .textAlign(TextAlign.Center)
114      .fontColor("#CCFFFFFF")
115      .backgroundColor("#16A085")
116    Text("#2ECC71\nEMERALD")
117      .fontWeight(FontWeight.Bold)
118      .fontSize(14)
119      .width("100%")
120      .textAlign(TextAlign.Center)
121      .fontColor("#CCFFFFFF")
122      .backgroundColor("#2ECC71")
123    Text("#27AE60\nNEPHRITIS")
124      .fontWeight(FontWeight.Bold)
125      .fontSize(14)
126      .width("100%")
127      .textAlign(TextAlign.Center)
128      .fontColor("#CCFFFFFF")
129      .backgroundColor("#27AE60")
130    Text("#3498DB\nPETER RIVER")
131      .fontWeight(FontWeight.Bold)
132      .fontSize(14)
133      .width("100%")
134      .textAlign(TextAlign.Center)
135      .fontColor("#CCFFFFFF")
136      .backgroundColor("#3498DB")
137  }
138
139  //定义几个左侧的页签项目
140  private readonly tabItems: Array<TabTitleBarTabItem> =
141    [
142      { title: '页签1' },
143      { title: '页签2' },
144      { title: '页签3' },
145      { title: 'icon', icon: $r('sys.media.ohos_app_icon') },
146      { title: '页签4' },
147    ]
148  //定义几个右侧的菜单项目
149  private readonly menuItems: Array<TabTitleBarMenuItem> = [
150    {
151      value: $r('sys.media.ohos_save_button_filled'),
152      isEnabled: true,
153      action: () => Prompt.showToast({ message: "on item click! index 0" })
154    },
155    {
156      value: $r('sys.media.ohos_ic_public_copy'),
157      isEnabled: true,
158      action: () => Prompt.showToast({ message: "on item click! index 1" })
159    },
160    {
161      value: $r('sys.media.ohos_ic_public_edit'),
162      isEnabled: true,
163      action: () => Prompt.showToast({ message: "on item click! index 2" })
164    },
165  ]
166
167  //TabTitleBar效果展示
168  build() {
169    Row() {
170      Column() {
171        TabTitleBar({
172          swiperContent: this.componentBuilder,
173          tabItems: this.tabItems,
174          menuItems: this.menuItems,
175        })
176      }.width('100%')
177    }.height('100%')
178  }
179}
180```
181
182![zh-cn_image_tabtitlebar_example01](figures/zh-cn_image_tabtitlebar_example01.png)
183
184### 示例2(右侧自定义按钮播报)
185从API version 18开始,该示例通过设置标题栏右侧自定义按钮属性accessibilityText、accessibilityDescription、accessibilityLevel自定义屏幕朗读播报文本。
186```ts
187import { TabTitleBar, Prompt, TabTitleBarTabItem, TabTitleBarMenuItem } from '@kit.ArkUI';
188
189@Entry
190@Component
191struct Index {
192  @Builder
193  //定义页签列表关联的页面
194  componentBuilder() {
195    Text("#1ABC9C\nTURQUOISE")
196      .fontWeight(FontWeight.Bold)
197      .fontSize(14)
198      .width("100%")
199      .textAlign(TextAlign.Center)
200      .fontColor("#CCFFFFFF")
201      .backgroundColor("#1ABC9C")
202    Text("#16A085\nGREEN SEA")
203      .fontWeight(FontWeight.Bold)
204      .fontSize(14)
205      .width("100%")
206      .textAlign(TextAlign.Center)
207      .fontColor("#CCFFFFFF")
208      .backgroundColor("#16A085")
209    Text("#2ECC71\nEMERALD")
210      .fontWeight(FontWeight.Bold)
211      .fontSize(14)
212      .width("100%")
213      .textAlign(TextAlign.Center)
214      .fontColor("#CCFFFFFF")
215      .backgroundColor("#2ECC71")
216    Text("#27AE60\nNEPHRITIS")
217      .fontWeight(FontWeight.Bold)
218      .fontSize(14)
219      .width("100%")
220      .textAlign(TextAlign.Center)
221      .fontColor("#CCFFFFFF")
222      .backgroundColor("#27AE60")
223    Text("#3498DB\nPETER RIVER")
224      .fontWeight(FontWeight.Bold)
225      .fontSize(14)
226      .width("100%")
227      .textAlign(TextAlign.Center)
228      .fontColor("#CCFFFFFF")
229      .backgroundColor("#3498DB")
230  }
231
232  //定义几个左侧的页签项目
233  private readonly tabItems: Array<TabTitleBarTabItem> =
234    [
235      { title: '页签1' },
236      { title: '页签2' },
237      { title: '页签3' },
238      { title: 'icon', icon: $r('sys.media.ohos_app_icon') },
239      { title: '页签4' },
240    ]
241  //定义几个右侧的菜单项目
242  private readonly menuItems: Array<TabTitleBarMenuItem> = [
243    {
244      value: $r('sys.media.ohos_save_button_filled'),
245      isEnabled: true,
246      action: () => Prompt.showToast({ message: "on item click! index 0" }),
247      accessibilityText: '保存',
248      //此处为no,屏幕朗读不聚焦
249      accessibilityLevel: 'no',
250      accessibilityDescription: '点击操作保存图标'
251    },
252    {
253      value: $r('sys.media.ohos_ic_public_copy'),
254      isEnabled: true,
255      action: () => Prompt.showToast({ message: "on item click! index 1" }),
256      accessibilityText: '复制',
257      accessibilityLevel: 'yes',
258      accessibilityDescription: '点击操作复制图标'
259    },
260    {
261      value: $r('sys.media.ohos_ic_public_edit'),
262      isEnabled: true,
263      action: () => Prompt.showToast({ message: "on item click! index 2" }),
264      //屏幕朗读播报文本,优先级比label高
265      accessibilityText: '编辑',
266      //屏幕朗读是否可以聚焦到
267      accessibilityLevel: 'yes',
268      //屏幕朗读最后播报的描述文本
269      accessibilityDescription: '点击操作编辑图标'
270    },
271  ]
272
273  //TabTitleBar效果展示
274  build() {
275    Row() {
276      Column() {
277        TabTitleBar({
278          swiperContent: this.componentBuilder,
279          tabItems: this.tabItems,
280          menuItems: this.menuItems,
281        })
282      }.width('100%')
283    }.height('100%')
284  }
285}
286```
287![zh-cn_image_tabtitlebar_example02](figures/zh-cn_image_tabtitlebar_example02.png)
288
289### 示例3(设置Symbol类型图标)
290从API version 18开始,该示例通过设置TabTitleBarTabItem、TabTitleBarMenuItem的属性symbolStyle,展示了自定义Symbol类型图标。
291```ts
292import { TabTitleBar, Prompt, TabTitleBarTabItem, TabTitleBarMenuItem, SymbolGlyphModifier } from '@kit.ArkUI';
293
294@Entry
295@Component
296struct Index {
297  @Builder
298  //定义页签列表关联的页面
299  componentBuilder() {
300    Text("#1ABC9C\nTURQUOISE")
301      .fontWeight(FontWeight.Bold)
302      .fontSize(14)
303      .width("100%")
304      .textAlign(TextAlign.Center)
305      .fontColor("#CCFFFFFF")
306      .backgroundColor("#1ABC9C")
307    Text("#16A085\nGREEN SEA")
308      .fontWeight(FontWeight.Bold)
309      .fontSize(14)
310      .width("100%")
311      .textAlign(TextAlign.Center)
312      .fontColor("#CCFFFFFF")
313      .backgroundColor("#16A085")
314    Text("#2ECC71\nEMERALD")
315      .fontWeight(FontWeight.Bold)
316      .fontSize(14)
317      .width("100%")
318      .textAlign(TextAlign.Center)
319      .fontColor("#CCFFFFFF")
320      .backgroundColor("#2ECC71")
321    Text("#27AE60\nNEPHRITIS")
322      .fontWeight(FontWeight.Bold)
323      .fontSize(14)
324      .width("100%")
325      .textAlign(TextAlign.Center)
326      .fontColor("#CCFFFFFF")
327      .backgroundColor("#27AE60")
328    Text("#3498DB\nPETER RIVER")
329      .fontWeight(FontWeight.Bold)
330      .fontSize(14)
331      .width("100%")
332      .textAlign(TextAlign.Center)
333      .fontColor("#CCFFFFFF")
334      .backgroundColor("#3498DB")
335  }
336
337  //定义几个左侧的页签项目
338  private readonly tabItems: Array<TabTitleBarTabItem> =
339    [
340      { title: '页签1' },
341      { title: '页签2' },
342      { title: '页签3' },
343      {
344        title: 'icon',
345        icon: $r('sys.media.ohos_app_icon'),
346        symbolStyle: new SymbolGlyphModifier($r('sys.symbol.car'))
347      },
348      { title: '页签4' },
349    ]
350  //定义几个右侧的菜单项目
351  private readonly menuItems: Array<TabTitleBarMenuItem> = [
352    {
353      value: $r('sys.media.ohos_save_button_filled'),
354      symbolStyle: new SymbolGlyphModifier($r('sys.symbol.save')),
355      isEnabled: true,
356      action: () => Prompt.showToast({ message: "on item click! index 0" }),
357      accessibilityText: '保存',
358      //此处为no,屏幕朗读不聚焦
359      accessibilityLevel: 'no',
360      accessibilityDescription: '点击操作保存图标'
361    },
362    {
363      value: $r('sys.media.ohos_ic_public_copy'),
364      symbolStyle: new SymbolGlyphModifier($r('sys.symbol.car')),
365      isEnabled: true,
366      action: () => Prompt.showToast({ message: "on item click! index 1" }),
367      accessibilityText: '复制',
368      accessibilityLevel: 'yes',
369      accessibilityDescription: '点击操作复制图标'
370    },
371    {
372      value: $r('sys.media.ohos_ic_public_edit'),
373      symbolStyle: new SymbolGlyphModifier($r('sys.symbol.ai_edit')),
374      isEnabled: true,
375      action: () => Prompt.showToast({ message: "on item click! index 2" }),
376      //屏幕朗读播报文本,优先级比label高
377      accessibilityText: '编辑',
378      //屏幕朗读是否可以聚焦到
379      accessibilityLevel: 'yes',
380      //屏幕朗读最后播报的描述文本
381      accessibilityDescription: '点击操作编辑图标'
382    },
383  ]
384
385  //TabTitleBar效果展示
386  build() {
387    Row() {
388      Column() {
389        TabTitleBar({
390          swiperContent: this.componentBuilder,
391          tabItems: this.tabItems,
392          menuItems: this.menuItems,
393        })
394      }.width('100%')
395    }.height('100%')
396  }
397}
398```
399![zh-cn_image_tabtitlebar_example03](figures/zh-cn_image_tabtitlebar_example03.png)