1e41f4b71Sopenharmony_ci# TabContent 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe **TabContent** component is used only in the **Tabs** component. It corresponds to the content view of a switched tab page. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci## Child Components 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ciThis component supports only one child component. 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ci> **NOTE** 15e41f4b71Sopenharmony_ci> 16e41f4b71Sopenharmony_ci> Built-in components and custom components are allowed, with support for ([if/else](../../../quick-start/arkts-rendering-control-ifelse.md), [ForEach](../../../quick-start/arkts-rendering-control-foreach.md), and [LazyForEach](../../../quick-start/arkts-rendering-control-lazyforeach.md)) rendering control. 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci## APIs 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ciTabContent() 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci## Attributes 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ciIn addition to the [universal attributes](ts-universal-attributes-size.md), the following attributes are supported. 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci### tabBar 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_citabBar(value: string | Resource | CustomBuilder | { icon?: string | Resource; text?: string | Resource }) 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ciContent displayed on the tab bar. 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ciIf an icon uses an SVG image, the width and height attributes of the SVG image must be deleted. Otherwise, the icon size will be determined by the width and height attributes of the SVG image. 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ciIf the content set exceeds the space provided by the tab bar, it will be clipped. 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_ci**Parameters** 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 48e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 49e41f4b71Sopenharmony_ci| value | string \| [Resource](ts-types.md#resource) \|<br>[CustomBuilder](ts-types.md#custombuilder8)<sup>8+</sup>\| {<br>icon?: string \| [Resource](ts-types.md#resource),<br>text?: string \| [Resource](ts-types.md#resource)<br>} | Yes| Content displayed on the tab bar.<br>**CustomBuilder**: builder, to which components can be passed (applicable to API version 8 and later versions).| 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ci### tabBar<sup>9+</sup> 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_citabBar(value: SubTabBarStyle | BottomTabBarStyle) 54e41f4b71Sopenharmony_ci 55e41f4b71Sopenharmony_ciSets the content displayed on the tab bar. The bottom tab style does not include an indicator. When an icon display error occurs, a gray blank block is displayed. 56e41f4b71Sopenharmony_ci 57e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 58e41f4b71Sopenharmony_ci 59e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ci**Parameters** 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 64e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 65e41f4b71Sopenharmony_ci| value | [SubTabBarStyle](#subtabbarstyle9) \| [BottomTabBarStyle](#bottomtabbarstyle9)| Yes | Content displayed on the tab bar.<br>**SubTabBarStyle**: subtab style<br>**BottomTabBarStyle**: bottom and side tab style| 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_ci> **NOTE** 68e41f4b71Sopenharmony_ci> 69e41f4b71Sopenharmony_ci> - The **TabContent** component does not support setting of the common width attribute. By default, its width is the same as that of the parent **Tabs** component. 70e41f4b71Sopenharmony_ci> - The **TabContent** component does not support setting of the universal height attribute. Its height is determined by the height of the parent **Tabs** component and the **TabBar** component. 71e41f4b71Sopenharmony_ci> - If the **vertical** attribute is **false**, the width and height descriptions are swapped in the preceding two restrictions. 72e41f4b71Sopenharmony_ci> - **TabContent** does not support page scrolling. If page scrolling is required, consider nesting a list. 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ci## SubTabBarStyle<sup>9+</sup> 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ciImplements the subtab style. When this attribute is enabled, the transition animation is played when the user switches between tabs. 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ci### constructor 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ciconstructor(content: ResourceStr) 81e41f4b71Sopenharmony_ci 82e41f4b71Sopenharmony_ciConstructor used to create a **SubTabBarStyle** instance. 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 85e41f4b71Sopenharmony_ci 86e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 87e41f4b71Sopenharmony_ci 88e41f4b71Sopenharmony_ci**Parameters** 89e41f4b71Sopenharmony_ci 90e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description| 91e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 92e41f4b71Sopenharmony_ci| content | [ResourceStr](ts-types.md#resourcestr) | Yes| Text for the tab.| 93e41f4b71Sopenharmony_ci 94e41f4b71Sopenharmony_ci### constructor<sup>12+</sup> 95e41f4b71Sopenharmony_ci 96e41f4b71Sopenharmony_ciconstructor(content: ResourceStr | ComponentContent) 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ciConstructor used to create a **SubTabBarStyle** instance. You can set custom content with **ComponentContent**. 99e41f4b71Sopenharmony_ci 100e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 103e41f4b71Sopenharmony_ci 104e41f4b71Sopenharmony_ci**Parameters** 105e41f4b71Sopenharmony_ci 106e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description| 107e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 108e41f4b71Sopenharmony_ci| content | [ResourceStr](ts-types.md#resourcestr) \| [ComponentContent](../js-apis-arkui-ComponentContent.md) | Yes| Content on the tab.<br>**NOTE**<br>1. Custom content does not support the **labelStyle** attribute.<br>2. If the custom content exceeds the content box of the tab page, the excess part is not displayed.<br>3. If the custom content is within the content box of the tab page, it is aligned in the center.<br>4. If the custom content is abnormal or no display component is available, a blank area is displayed.| 109e41f4b71Sopenharmony_ci 110e41f4b71Sopenharmony_ci### of<sup>10+</sup> 111e41f4b71Sopenharmony_ci 112e41f4b71Sopenharmony_cistatic of(content: ResourceStr): SubTabBarStyle 113e41f4b71Sopenharmony_ci 114e41f4b71Sopenharmony_ciStatic constructor used to create a **SubTabBarStyle** instance. 115e41f4b71Sopenharmony_ci 116e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 117e41f4b71Sopenharmony_ci 118e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 119e41f4b71Sopenharmony_ci 120e41f4b71Sopenharmony_ci**Parameters** 121e41f4b71Sopenharmony_ci 122e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 123e41f4b71Sopenharmony_ci| ------- | ------------------------------------------ | ---- | ------------------ | 124e41f4b71Sopenharmony_ci| content | [ResourceStr](ts-types.md#resourcestr) | Yes | Text for the tab.| 125e41f4b71Sopenharmony_ci 126e41f4b71Sopenharmony_ci**Return value** 127e41f4b71Sopenharmony_ci 128e41f4b71Sopenharmony_ci| Type | Description | 129e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ | 130e41f4b71Sopenharmony_ci| [SubTabBarStyle](#subtabbarstyle9) | **SubTabBarStyle** object created.| 131e41f4b71Sopenharmony_ci 132e41f4b71Sopenharmony_ci### of<sup>12+</sup> 133e41f4b71Sopenharmony_ci 134e41f4b71Sopenharmony_cistatic of(content: ResourceStr | ComponentContent): SubTabBarStyle 135e41f4b71Sopenharmony_ci 136e41f4b71Sopenharmony_ciStatic constructor used to create a **SubTabBarStyle** instance. 137e41f4b71Sopenharmony_ci 138e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 139e41f4b71Sopenharmony_ci 140e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 141e41f4b71Sopenharmony_ci 142e41f4b71Sopenharmony_ci**Parameters** 143e41f4b71Sopenharmony_ci 144e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 145e41f4b71Sopenharmony_ci| ------- | ------------------------------------------ | ---- | ------------------ | 146e41f4b71Sopenharmony_ci| content | [ResourceStr](ts-types.md#resourcestr) \| [ComponentContent](../js-apis-arkui-ComponentContent.md) | Yes | Content on the tab. You can set custom content with **ComponentContent**.<br>**NOTE**<br>1. Custom content does not support the **labelStyle** attribute.<br>2. If the custom content exceeds the content box of the tab page, the excess part is not displayed.<br>3. If the custom content is within the content box of the tab page, it is aligned in the center.<br>4. If the custom content is abnormal or no display component is available, a blank area is displayed.| 147e41f4b71Sopenharmony_ci 148e41f4b71Sopenharmony_ci**Return value** 149e41f4b71Sopenharmony_ci 150e41f4b71Sopenharmony_ci| Type | Description | 151e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ | 152e41f4b71Sopenharmony_ci| [SubTabBarStyle](#subtabbarstyle9) | **SubTabBarStyle** object created.| 153e41f4b71Sopenharmony_ci 154e41f4b71Sopenharmony_ci### Attributes 155e41f4b71Sopenharmony_ci 156e41f4b71Sopenharmony_ciThe following attributes are supported. 157e41f4b71Sopenharmony_ci 158e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 159e41f4b71Sopenharmony_ci 160e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 161e41f4b71Sopenharmony_ci| ----------- | ----------------- | ---- |---------------------------------------- | 162e41f4b71Sopenharmony_ci| indicator<sup>10+</sup> | [IndicatorStyle](#indicatorstyle10)| Yes| Indicator style of the selected subtab. It takes effect only in the horizontal layout.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 163e41f4b71Sopenharmony_ci| selectedMode<sup>10+</sup> | [SelectedMode](#selectedmode10) | Yes| Display mode of the selected subtab. It takes effect only in the horizontal layout.<br>Default value: **SelectedMode.INDICATOR**<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 164e41f4b71Sopenharmony_ci| board<sup>10+</sup> | [BoardStyle](#boardstyle10) | Yes| Board style of the selected subtab. It takes effect only in the horizontal layout.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 165e41f4b71Sopenharmony_ci| labelStyle<sup>10+</sup> | [LabelStyle](#labelstyle10) | Yes| Label text and font of the subtab.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 166e41f4b71Sopenharmony_ci| padding<sup>10+</sup> | [Padding](ts-types.md#padding) \| [Dimension](ts-types.md#dimension10) | Yes| Padding of the subtab. It cannot be set in percentage. When the parameter is of the Dimension type, the value applies to all sides.<br>Default value: **{left:8.0vp,right:8.0vp,top:17.0vp,bottom:18.0vp}**<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 167e41f4b71Sopenharmony_ci| padding<sup>12+</sup> | [LocalizedPadding](ts-types.md#localizedpadding12) | Yes| Padding of the subtab. The mirroring capability is supported (percentage values are not allowed).<br>Default value: {start:LengthMetircs.vp(8),end:LengthMetircs.vp(8),<br>top:LengthMetircs.vp(17),bottom:LengthMetircs.vp(18)}<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 168e41f4b71Sopenharmony_ci| id<sup>11+</sup> | string | Yes| [ID](ts-universal-attributes-component-id.md#attributes) of the subtab.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 169e41f4b71Sopenharmony_ci 170e41f4b71Sopenharmony_ci## IndicatorStyle<sup>10+</sup> 171e41f4b71Sopenharmony_ci 172e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 173e41f4b71Sopenharmony_ci 174e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 175e41f4b71Sopenharmony_ci 176e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 177e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------------------------------- | 178e41f4b71Sopenharmony_ci| color | [ResourceColor](ts-types.md#resourcecolor) | No| Color of the indicator and board.<br>Default value: **#FF007DFF**| 179e41f4b71Sopenharmony_ci| height | [Length](ts-types.md#length) | No| Height of the indicator. It cannot be set in percentage.<br>Default value: **2.0**<br>Unit: vp| 180e41f4b71Sopenharmony_ci| width | [Length](ts-types.md#length) | No| Width of the indicator. It cannot be set in percentage.<br>Default value: **0.0**<br>Unit: vp<br>**NOTE**<br>If this parameter is set to **0**, the tab text width will be used instead.| 181e41f4b71Sopenharmony_ci| borderRadius | [Length](ts-types.md#length) | No| Rounded corner radius of the indicator. It cannot be set in percentage.<br>Default value: **0.0**<br>Unit: vp| 182e41f4b71Sopenharmony_ci| marginTop | [Length](ts-types.md#length) | No| Spacing between the indicator and text. It cannot be set in percentage.<br>Default value: **8.0**<br>Unit: vp| 183e41f4b71Sopenharmony_ci 184e41f4b71Sopenharmony_ci## SelectedMode<sup>10+</sup> 185e41f4b71Sopenharmony_ci 186e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 187e41f4b71Sopenharmony_ci 188e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 189e41f4b71Sopenharmony_ci 190e41f4b71Sopenharmony_ci| Name | Description | 191e41f4b71Sopenharmony_ci| ---------- | ------------------------ | 192e41f4b71Sopenharmony_ci| INDICATOR | Indicator mode. | 193e41f4b71Sopenharmony_ci| BOARD | Board mode. | 194e41f4b71Sopenharmony_ci 195e41f4b71Sopenharmony_ci## BoardStyle<sup>10+</sup> 196e41f4b71Sopenharmony_ci 197e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 198e41f4b71Sopenharmony_ci 199e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 200e41f4b71Sopenharmony_ci 201e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 202e41f4b71Sopenharmony_ci| -------- | -------- | -------- | ------------------------------------ | 203e41f4b71Sopenharmony_ci| borderRadius | [Length](ts-types.md#length) | No| Rounded corner radius of the board. It cannot be set in percentage.<br>Default value: **8.0**<br>Unit: vp| 204e41f4b71Sopenharmony_ci 205e41f4b71Sopenharmony_ci## LabelStyle<sup>10+</sup> 206e41f4b71Sopenharmony_ci 207e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 208e41f4b71Sopenharmony_ci 209e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 210e41f4b71Sopenharmony_ci| -------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 211e41f4b71Sopenharmony_ci| overflow | [TextOverflow](ts-appendix-enums.md#textoverflow) | No | Display mode when the label text is too long. By default, an ellipsis (...) is used to represent text overflow.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 212e41f4b71Sopenharmony_ci| maxLines | number | No | Maximum number of lines in the label text. If this attribute is specified, the text will not exceed the specified number of lines. You can use **textOverflow** to specify how to represent text overflow. Default value: **1**<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 213e41f4b71Sopenharmony_ci| minFontSize | number \| [ResourceStr](ts-types.md#resourcestr) | No | Minimum font size of the label text. It cannot be set in percentage. For the setting to take effect, this attribute must be used together with **maxFontSize**, **maxLines**, or layout constraint settings. When the adaptive text size is set, **font.size** does not take effect. Default value: **0.0fp**<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 214e41f4b71Sopenharmony_ci| maxFontSize | number \| [ResourceStr](ts-types.md#resourcestr) | No | Maximum font size of the label text. It cannot be set in percentage. For the setting to take effect, this attribute must be used together with **minFontSize**, **maxLines**, or layout constraint settings. When the adaptive text size is set, **font.size** does not take effect. Default value: **0.0fp**<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 215e41f4b71Sopenharmony_ci| heightAdaptivePolicy | [TextHeightAdaptivePolicy](ts-appendix-enums.md#textheightadaptivepolicy10) | No | How the adaptive height is determined for the label text. By default, the **maxLines** settings are prioritized.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 216e41f4b71Sopenharmony_ci| font | [Font](ts-types.md#font) | No | Font of the label text.<br>When the tab is a subtab, the default font is in 16.0 fp size, 'HarmonyOS Sans' family, and normal font style and weight.<br>When the tab is a bottom tab, the default font is in 10.0 fp size, 'HarmonyOS Sans' family, normal font style, and medium weight.<br>The default font size of the bottom tab page is 12.0 fp since API version 12.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 217e41f4b71Sopenharmony_ci| unselectedColor<sup>12+</sup> | [ResourceColor](ts-types.md#resourcecolor) | No| Font color of the label text when it is not selected.<br>Default value: **#99182431**<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 218e41f4b71Sopenharmony_ci| selectedColor<sup>12+</sup> | [ResourceColor](ts-types.md#resourcecolor) | No| Font color of the label text when it is selected.<br>Default value: **#FF007DFF**<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 219e41f4b71Sopenharmony_ci 220e41f4b71Sopenharmony_ci## BottomTabBarStyle<sup>9+</sup> 221e41f4b71Sopenharmony_ci 222e41f4b71Sopenharmony_ciImplements the bottom and side tab style. 223e41f4b71Sopenharmony_ci 224e41f4b71Sopenharmony_ci### constructor 225e41f4b71Sopenharmony_ci 226e41f4b71Sopenharmony_ciconstructor(icon: ResourceStr | TabBarSymbol, text: ResourceStr) 227e41f4b71Sopenharmony_ci 228e41f4b71Sopenharmony_ciA constructor used to create a **BottomTabBarStyle** instance. 229e41f4b71Sopenharmony_ci 230e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 231e41f4b71Sopenharmony_ci 232e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 233e41f4b71Sopenharmony_ci 234e41f4b71Sopenharmony_ci**Parameters** 235e41f4b71Sopenharmony_ci 236e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description| 237e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 238e41f4b71Sopenharmony_ci| icon | [ResourceStr](ts-types.md#resourcestr) \| [TabBarSymbol<sup>12+</sup>](#tabbarsymbol12)| Yes| Image for the tab.| 239e41f4b71Sopenharmony_ci| text | [ResourceStr](ts-types.md#resourcestr) | Yes| Text for the tab.| 240e41f4b71Sopenharmony_ci 241e41f4b71Sopenharmony_ci### of<sup>10+</sup> 242e41f4b71Sopenharmony_ci 243e41f4b71Sopenharmony_cistatic of(icon: ResourceStr | TabBarSymbol, text: ResourceStr): BottomTabBarStyle 244e41f4b71Sopenharmony_ci 245e41f4b71Sopenharmony_ciStatic constructor used to create a **BottomTabBarStyle** instance. 246e41f4b71Sopenharmony_ci 247e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 248e41f4b71Sopenharmony_ci 249e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 250e41f4b71Sopenharmony_ci 251e41f4b71Sopenharmony_ci**Parameters** 252e41f4b71Sopenharmony_ci 253e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description| 254e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 255e41f4b71Sopenharmony_ci| icon | [ResourceStr](ts-types.md#resourcestr) \| [TabBarSymbol<sup>12+</sup>](#tabbarsymbol12)| Yes| Image for the tab.| 256e41f4b71Sopenharmony_ci| text | [ResourceStr](ts-types.md#resourcestr) | Yes| Text for the tab.| 257e41f4b71Sopenharmony_ci 258e41f4b71Sopenharmony_ci**Return value** 259e41f4b71Sopenharmony_ci 260e41f4b71Sopenharmony_ci| Type | Description | 261e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ | 262e41f4b71Sopenharmony_ci| [BottomTabBarStyle](#bottomtabbarstyle9)| **BottomTabBarStyle** object created.| 263e41f4b71Sopenharmony_ci 264e41f4b71Sopenharmony_ci### Attributes 265e41f4b71Sopenharmony_ci 266e41f4b71Sopenharmony_ciThe following attributes are supported. 267e41f4b71Sopenharmony_ci 268e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 269e41f4b71Sopenharmony_ci 270e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 271e41f4b71Sopenharmony_ci| ------------ | ---------------------------- | ---- |----------------------------------- | 272e41f4b71Sopenharmony_ci| padding<sup>10+</sup> | [Padding](ts-types.md#padding) \| [Dimension](ts-types.md#dimension10) \| [LocalizedPadding<sup>12+</sup>](ts-types.md#localizedpadding12) | Yes| Padding of the bottom tab. It cannot be set in percentage. When the parameter is of the Dimension type, the value applies to all sides.<br>Default value: **{left:4.0vp,right:4.0vp,top:0.0vp,bottom:0.0vp}**<br>If of the LocalizedPadding type, this attribute supports the mirroring capability.<br>Default value: {start:LengthMetircs.vp(4),end:LengthMetircs.vp(4),<br>top:LengthMetircs.vp(0),bottom:LengthMetircs.vp(0)}<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 273e41f4b71Sopenharmony_ci| verticalAlign<sup>10+</sup> | [VerticalAlign](ts-appendix-enums.md#verticalalign) | Yes| Vertical alignment mode of the images and text on the bottom tab.<br>Default value: **VerticalAlign.Center**<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 274e41f4b71Sopenharmony_ci| layoutMode<sup>10+</sup> | [LayoutMode](#layoutmode10) | Yes| Layout of the images and text on the bottom tab. For details, see **LayoutMode**.<br>Default value: **LayoutMode.VERTICAL**<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 275e41f4b71Sopenharmony_ci| symmetricExtensible<sup>10+</sup> | boolean | Yes| Whether the images and text on the bottom tab can be symmetrically extended by the minimum value of the available space on the left and right bottom tabs. This parameter is valid only between bottom tabs in fixed horizontal mode.<br>Default value: **false**<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 276e41f4b71Sopenharmony_ci| labelStyle<sup>10+</sup> | [LabelStyle](#labelstyle10) | Yes| Label text and font of the bottom tab.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 277e41f4b71Sopenharmony_ci| id<sup>11+</sup> | string | Yes| [ID](ts-universal-attributes-component-id.md#attributes) of the bottom tab.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 278e41f4b71Sopenharmony_ci| iconStyle<sup>12+</sup> | [TabBarIconStyle](#tabbariconstyle12) | Yes| Style of the label icon on the bottom tab.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 279e41f4b71Sopenharmony_ci 280e41f4b71Sopenharmony_ci## TabBarSymbol<sup>12+</sup> 281e41f4b71Sopenharmony_ci 282e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 283e41f4b71Sopenharmony_ci 284e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 285e41f4b71Sopenharmony_ci 286e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description| 287e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 288e41f4b71Sopenharmony_ci| normal | [SymbolGlyphModifier](ts-universal-attributes-attribute-modifier.md) | Yes| Symbol icon in the normal style.<br>Default value:<br>**fontColor**: **#66182431**, **renderingStrategy**: **SymbolRenderingStrategy.MULTIPLE_OPACITY**, **fontSize**: **24vp**| 289e41f4b71Sopenharmony_ci| selected | [SymbolGlyphModifier](ts-universal-attributes-attribute-modifier.md) | No| Symbol icon in the selected style.<br>Default value:<br>**fontColor**: **#ff007dff**, **renderingStrategy**: **SymbolRenderingStrategy.MULTIPLE_OPACITY**, **fontSize**: **24vp**| 290e41f4b71Sopenharmony_ci 291e41f4b71Sopenharmony_ci## LayoutMode<sup>10+</sup> 292e41f4b71Sopenharmony_ci 293e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 294e41f4b71Sopenharmony_ci 295e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 296e41f4b71Sopenharmony_ci 297e41f4b71Sopenharmony_ci| Name | Description | 298e41f4b71Sopenharmony_ci| ---------- | ---------------------------------------- | 299e41f4b71Sopenharmony_ci| AUTO | When the tab width is greater than 104 vp, the tab content is arranged from left to right. Otherwise,the tab content is arranged from top to bottom. This parameter is valid only when the tab bar is in vertical mode or fixed horizontal mode.| 300e41f4b71Sopenharmony_ci| VERTICAL | The tab content is arranged from top to bottom.| 301e41f4b71Sopenharmony_ci| HORIZONTAL | The tab content is arranged from left to right.| 302e41f4b71Sopenharmony_ci 303e41f4b71Sopenharmony_ci## TabBarIconStyle<sup>12+</sup> 304e41f4b71Sopenharmony_ci 305e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 306e41f4b71Sopenharmony_ci 307e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 308e41f4b71Sopenharmony_ci 309e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 310e41f4b71Sopenharmony_ci| -------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 311e41f4b71Sopenharmony_ci| unselectedColor | [ResourceColor](ts-types.md#resourcecolor) | No| Color of the label icon when it is not selected.<br>Default value: **#33182431**<br>**NOTE**<br>This attribute only applies to an SVG image. Once set, the fill color will replace that of the SVG image.| 312e41f4b71Sopenharmony_ci| selectedColor | [ResourceColor](ts-types.md#resourcecolor) | No| Color of the label icon when it is selected.<br>Default value: **#FF007DFF**<br>**NOTE**<br>This attribute only applies to an SVG image. Once set, the fill color will replace that of the SVG image.| 313e41f4b71Sopenharmony_ci 314e41f4b71Sopenharmony_ci## Events 315e41f4b71Sopenharmony_ci 316e41f4b71Sopenharmony_ciIn addition to the [universal events](ts-universal-events-click.md), the following events are supported. 317e41f4b71Sopenharmony_ci 318e41f4b71Sopenharmony_ci### onWillShow<sup>12+</sup> 319e41f4b71Sopenharmony_ci 320e41f4b71Sopenharmony_cionWillShow(event: VoidCallback) 321e41f4b71Sopenharmony_ci 322e41f4b71Sopenharmony_ciCalled when the tab content is about to be displayed. The scenarios include the first-time display, tab switching, page switching, and window switching between the foreground and background. 323e41f4b71Sopenharmony_ci 324e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 325e41f4b71Sopenharmony_ci 326e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 327e41f4b71Sopenharmony_ci 328e41f4b71Sopenharmony_ci**Parameters** 329e41f4b71Sopenharmony_ci 330e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 331e41f4b71Sopenharmony_ci| ------ | --------------------------------------------- | ---- | ----------------------------------- | 332e41f4b71Sopenharmony_ci| event | [VoidCallback](ts-types.md#voidcallback12) | Yes | Callback for when the tab content is about to be displayed. | 333e41f4b71Sopenharmony_ci 334e41f4b71Sopenharmony_ci### onWillHide<sup>12+</sup> 335e41f4b71Sopenharmony_ci 336e41f4b71Sopenharmony_cionWillHide(event: VoidCallback) 337e41f4b71Sopenharmony_ci 338e41f4b71Sopenharmony_ciCalled when the tab content is about to be hidden. The scenarios include the tab switching, page switching, and window switching between the foreground and background. 339e41f4b71Sopenharmony_ci 340e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 341e41f4b71Sopenharmony_ci 342e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 343e41f4b71Sopenharmony_ci 344e41f4b71Sopenharmony_ci**Parameters** 345e41f4b71Sopenharmony_ci 346e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 347e41f4b71Sopenharmony_ci| ------ | --------------------------------------------- | ---- | ----------------------------------- | 348e41f4b71Sopenharmony_ci| event | [VoidCallback](ts-types.md#voidcallback12) | Yes | Callback for when the tab content is about to be hidden. | 349e41f4b71Sopenharmony_ci 350e41f4b71Sopenharmony_ci## Example 351e41f4b71Sopenharmony_ci 352e41f4b71Sopenharmony_ci### Example 1 353e41f4b71Sopenharmony_ci 354e41f4b71Sopenharmony_ci```ts 355e41f4b71Sopenharmony_ci// xxx.ets 356e41f4b71Sopenharmony_ci@Entry 357e41f4b71Sopenharmony_ci@Component 358e41f4b71Sopenharmony_cistruct TabContentExample { 359e41f4b71Sopenharmony_ci @State fontColor: string = '#182431' 360e41f4b71Sopenharmony_ci @State selectedFontColor: string = '#007DFF' 361e41f4b71Sopenharmony_ci @State currentIndex: number = 0 362e41f4b71Sopenharmony_ci private controller: TabsController = new TabsController() 363e41f4b71Sopenharmony_ci 364e41f4b71Sopenharmony_ci @Builder tabBuilder(index: number) { 365e41f4b71Sopenharmony_ci Column() { 366e41f4b71Sopenharmony_ci Image(this.currentIndex === index ? '/common/public_icon_on.svg' : '/common/public_icon_off.svg') 367e41f4b71Sopenharmony_ci .width(24) 368e41f4b71Sopenharmony_ci .height(24) 369e41f4b71Sopenharmony_ci .margin({ bottom: 4 }) 370e41f4b71Sopenharmony_ci .objectFit(ImageFit.Contain) 371e41f4b71Sopenharmony_ci Text(`Tab${index + 1}`) 372e41f4b71Sopenharmony_ci .fontColor(this.currentIndex === index ? this.selectedFontColor : this.fontColor) 373e41f4b71Sopenharmony_ci .fontSize(10) 374e41f4b71Sopenharmony_ci .fontWeight(500) 375e41f4b71Sopenharmony_ci .lineHeight(14) 376e41f4b71Sopenharmony_ci }.width('100%') 377e41f4b71Sopenharmony_ci } 378e41f4b71Sopenharmony_ci 379e41f4b71Sopenharmony_ci build() { 380e41f4b71Sopenharmony_ci Column() { 381e41f4b71Sopenharmony_ci Tabs({ barPosition: BarPosition.End, controller: this.controller }) { 382e41f4b71Sopenharmony_ci TabContent() { 383e41f4b71Sopenharmony_ci Column() { 384e41f4b71Sopenharmony_ci Text('Tab1') 385e41f4b71Sopenharmony_ci .fontSize(36) 386e41f4b71Sopenharmony_ci .fontColor('#182431') 387e41f4b71Sopenharmony_ci .fontWeight(500) 388e41f4b71Sopenharmony_ci .opacity(0.4) 389e41f4b71Sopenharmony_ci .margin({ top: 30, bottom: 56.5 }) 390e41f4b71Sopenharmony_ci Divider() 391e41f4b71Sopenharmony_ci .strokeWidth(0.5) 392e41f4b71Sopenharmony_ci .color('#182431') 393e41f4b71Sopenharmony_ci .opacity(0.05) 394e41f4b71Sopenharmony_ci }.width('100%') 395e41f4b71Sopenharmony_ci }.tabBar(this.tabBuilder(0)) 396e41f4b71Sopenharmony_ci 397e41f4b71Sopenharmony_ci TabContent() { 398e41f4b71Sopenharmony_ci Column() { 399e41f4b71Sopenharmony_ci Text('Tab2') 400e41f4b71Sopenharmony_ci .fontSize(36) 401e41f4b71Sopenharmony_ci .fontColor('#182431') 402e41f4b71Sopenharmony_ci .fontWeight(500) 403e41f4b71Sopenharmony_ci .opacity(0.4) 404e41f4b71Sopenharmony_ci .margin({ top: 30, bottom: 56.5 }) 405e41f4b71Sopenharmony_ci Divider() 406e41f4b71Sopenharmony_ci .strokeWidth(0.5) 407e41f4b71Sopenharmony_ci .color('#182431') 408e41f4b71Sopenharmony_ci .opacity(0.05) 409e41f4b71Sopenharmony_ci }.width('100%') 410e41f4b71Sopenharmony_ci }.tabBar(this.tabBuilder(1)) 411e41f4b71Sopenharmony_ci 412e41f4b71Sopenharmony_ci TabContent() { 413e41f4b71Sopenharmony_ci Column() { 414e41f4b71Sopenharmony_ci Text('Tab3') 415e41f4b71Sopenharmony_ci .fontSize(36) 416e41f4b71Sopenharmony_ci .fontColor('#182431') 417e41f4b71Sopenharmony_ci .fontWeight(500) 418e41f4b71Sopenharmony_ci .opacity(0.4) 419e41f4b71Sopenharmony_ci .margin({ top: 30, bottom: 56.5 }) 420e41f4b71Sopenharmony_ci Divider() 421e41f4b71Sopenharmony_ci .strokeWidth(0.5) 422e41f4b71Sopenharmony_ci .color('#182431') 423e41f4b71Sopenharmony_ci .opacity(0.05) 424e41f4b71Sopenharmony_ci }.width('100%') 425e41f4b71Sopenharmony_ci }.tabBar(this.tabBuilder(2)) 426e41f4b71Sopenharmony_ci 427e41f4b71Sopenharmony_ci TabContent() { 428e41f4b71Sopenharmony_ci Column() { 429e41f4b71Sopenharmony_ci Text('Tab4') 430e41f4b71Sopenharmony_ci .fontSize(36) 431e41f4b71Sopenharmony_ci .fontColor('#182431') 432e41f4b71Sopenharmony_ci .fontWeight(500) 433e41f4b71Sopenharmony_ci .opacity(0.4) 434e41f4b71Sopenharmony_ci .margin({ top: 30, bottom: 56.5 }) 435e41f4b71Sopenharmony_ci Divider() 436e41f4b71Sopenharmony_ci .strokeWidth(0.5) 437e41f4b71Sopenharmony_ci .color('#182431') 438e41f4b71Sopenharmony_ci .opacity(0.05) 439e41f4b71Sopenharmony_ci }.width('100%') 440e41f4b71Sopenharmony_ci }.tabBar(this.tabBuilder(3)) 441e41f4b71Sopenharmony_ci } 442e41f4b71Sopenharmony_ci .vertical(false) 443e41f4b71Sopenharmony_ci .barHeight(56) 444e41f4b71Sopenharmony_ci .onChange((index: number) => { 445e41f4b71Sopenharmony_ci this.currentIndex = index 446e41f4b71Sopenharmony_ci }) 447e41f4b71Sopenharmony_ci .width(360) 448e41f4b71Sopenharmony_ci .height(190) 449e41f4b71Sopenharmony_ci .backgroundColor('#F1F3F5') 450e41f4b71Sopenharmony_ci .margin({ top: 38 }) 451e41f4b71Sopenharmony_ci }.width('100%') 452e41f4b71Sopenharmony_ci } 453e41f4b71Sopenharmony_ci} 454e41f4b71Sopenharmony_ci``` 455e41f4b71Sopenharmony_ci 456e41f4b71Sopenharmony_ci 457e41f4b71Sopenharmony_ci 458e41f4b71Sopenharmony_ci### Example 2 459e41f4b71Sopenharmony_ci 460e41f4b71Sopenharmony_ci```ts 461e41f4b71Sopenharmony_ci// xxx.ets 462e41f4b71Sopenharmony_ci@Entry 463e41f4b71Sopenharmony_ci@Component 464e41f4b71Sopenharmony_cistruct TabContentExample { 465e41f4b71Sopenharmony_ci @State fontColor: string = '#182431' 466e41f4b71Sopenharmony_ci @State selectedFontColor: string = '#007DFF' 467e41f4b71Sopenharmony_ci @State currentIndex: number = 0 468e41f4b71Sopenharmony_ci private controller: TabsController = new TabsController() 469e41f4b71Sopenharmony_ci 470e41f4b71Sopenharmony_ci @Builder tabBuilder(index: number) { 471e41f4b71Sopenharmony_ci Column() { 472e41f4b71Sopenharmony_ci Image(this.currentIndex === index ? '/common/public_icon_on.svg' : '/common/public_icon_off.svg') 473e41f4b71Sopenharmony_ci .width(24) 474e41f4b71Sopenharmony_ci .height(24) 475e41f4b71Sopenharmony_ci .margin({ bottom: 4 }) 476e41f4b71Sopenharmony_ci .objectFit(ImageFit.Contain) 477e41f4b71Sopenharmony_ci Text('Tab') 478e41f4b71Sopenharmony_ci .fontColor(this.currentIndex === index ? this.selectedFontColor : this.fontColor) 479e41f4b71Sopenharmony_ci .fontSize(10) 480e41f4b71Sopenharmony_ci .fontWeight(500) 481e41f4b71Sopenharmony_ci .lineHeight(14) 482e41f4b71Sopenharmony_ci }.width('100%').height('100%').justifyContent(FlexAlign.Center) 483e41f4b71Sopenharmony_ci } 484e41f4b71Sopenharmony_ci 485e41f4b71Sopenharmony_ci build() { 486e41f4b71Sopenharmony_ci Column() { 487e41f4b71Sopenharmony_ci Tabs({ barPosition: BarPosition.Start, controller: this.controller }) { 488e41f4b71Sopenharmony_ci TabContent() 489e41f4b71Sopenharmony_ci .tabBar(this.tabBuilder(0)) 490e41f4b71Sopenharmony_ci TabContent() 491e41f4b71Sopenharmony_ci .tabBar(this.tabBuilder(1)) 492e41f4b71Sopenharmony_ci TabContent() 493e41f4b71Sopenharmony_ci .tabBar(this.tabBuilder(2)) 494e41f4b71Sopenharmony_ci TabContent() 495e41f4b71Sopenharmony_ci .tabBar(this.tabBuilder(3)) 496e41f4b71Sopenharmony_ci } 497e41f4b71Sopenharmony_ci .vertical(true) 498e41f4b71Sopenharmony_ci .barWidth(96) 499e41f4b71Sopenharmony_ci .barHeight(414) 500e41f4b71Sopenharmony_ci .onChange((index: number) => { 501e41f4b71Sopenharmony_ci this.currentIndex = index 502e41f4b71Sopenharmony_ci }) 503e41f4b71Sopenharmony_ci .width(96) 504e41f4b71Sopenharmony_ci .height(414) 505e41f4b71Sopenharmony_ci .backgroundColor('#F1F3F5') 506e41f4b71Sopenharmony_ci .margin({ top: 52 }) 507e41f4b71Sopenharmony_ci }.width('100%') 508e41f4b71Sopenharmony_ci } 509e41f4b71Sopenharmony_ci} 510e41f4b71Sopenharmony_ci``` 511e41f4b71Sopenharmony_ci 512e41f4b71Sopenharmony_ci 513e41f4b71Sopenharmony_ci 514e41f4b71Sopenharmony_ci### Example 3 515e41f4b71Sopenharmony_ci 516e41f4b71Sopenharmony_ci```ts 517e41f4b71Sopenharmony_ci// xxx.ets 518e41f4b71Sopenharmony_ci@Entry 519e41f4b71Sopenharmony_ci@Component 520e41f4b71Sopenharmony_cistruct TabBarStyleExample { 521e41f4b71Sopenharmony_ci build() { 522e41f4b71Sopenharmony_ci Column({ space: 5 }) { 523e41f4b71Sopenharmony_ci Text ("Subtab Style") 524e41f4b71Sopenharmony_ci Column() { 525e41f4b71Sopenharmony_ci Tabs({ barPosition: BarPosition.Start }) { 526e41f4b71Sopenharmony_ci TabContent() { 527e41f4b71Sopenharmony_ci Column().width('100%').height('100%').backgroundColor(Color.Pink) 528e41f4b71Sopenharmony_ci }.tabBar(new SubTabBarStyle('Pink')) 529e41f4b71Sopenharmony_ci .onWillShow(() => { 530e41f4b71Sopenharmony_ci console.info("Pink will show") 531e41f4b71Sopenharmony_ci }) 532e41f4b71Sopenharmony_ci .onWillHide(() => { 533e41f4b71Sopenharmony_ci console.info("Pink will hide") 534e41f4b71Sopenharmony_ci }) 535e41f4b71Sopenharmony_ci 536e41f4b71Sopenharmony_ci TabContent() { 537e41f4b71Sopenharmony_ci Column().width('100%').height('100%').backgroundColor(Color.Yellow) 538e41f4b71Sopenharmony_ci }.tabBar(new SubTabBarStyle('Yellow')) 539e41f4b71Sopenharmony_ci .onWillShow(() => { 540e41f4b71Sopenharmony_ci console.info("Yellow will show") 541e41f4b71Sopenharmony_ci }) 542e41f4b71Sopenharmony_ci .onWillHide(() => { 543e41f4b71Sopenharmony_ci console.info("Yellow will hide") 544e41f4b71Sopenharmony_ci }) 545e41f4b71Sopenharmony_ci 546e41f4b71Sopenharmony_ci TabContent() { 547e41f4b71Sopenharmony_ci Column().width('100%').height('100%').backgroundColor(Color.Blue) 548e41f4b71Sopenharmony_ci }.tabBar(new SubTabBarStyle('Blue')) 549e41f4b71Sopenharmony_ci .onWillShow(() => { 550e41f4b71Sopenharmony_ci console.info("Blue will show") 551e41f4b71Sopenharmony_ci }) 552e41f4b71Sopenharmony_ci .onWillHide(() => { 553e41f4b71Sopenharmony_ci console.info("Blue will hide") 554e41f4b71Sopenharmony_ci }) 555e41f4b71Sopenharmony_ci 556e41f4b71Sopenharmony_ci TabContent() { 557e41f4b71Sopenharmony_ci Column().width('100%').height('100%').backgroundColor(Color.Green) 558e41f4b71Sopenharmony_ci }.tabBar(new SubTabBarStyle('Green')) 559e41f4b71Sopenharmony_ci .onWillShow(() => { 560e41f4b71Sopenharmony_ci console.info("Green will show") 561e41f4b71Sopenharmony_ci }) 562e41f4b71Sopenharmony_ci .onWillHide(() => { 563e41f4b71Sopenharmony_ci console.info("Green will hide") 564e41f4b71Sopenharmony_ci }) 565e41f4b71Sopenharmony_ci } 566e41f4b71Sopenharmony_ci .vertical(false) 567e41f4b71Sopenharmony_ci .scrollable(true) 568e41f4b71Sopenharmony_ci .barMode(BarMode.Fixed) 569e41f4b71Sopenharmony_ci .onChange((index: number) => { 570e41f4b71Sopenharmony_ci console.info(index.toString()) 571e41f4b71Sopenharmony_ci }) 572e41f4b71Sopenharmony_ci .width('100%') 573e41f4b71Sopenharmony_ci .backgroundColor(0xF1F3F5) 574e41f4b71Sopenharmony_ci }.width('100%').height(200) 575e41f4b71Sopenharmony_ci Text ("Bottom Tab Style") 576e41f4b71Sopenharmony_ci Column() { 577e41f4b71Sopenharmony_ci Tabs({ barPosition: BarPosition.End }) { 578e41f4b71Sopenharmony_ci TabContent() { 579e41f4b71Sopenharmony_ci Column().width('100%').height('100%').backgroundColor(Color.Pink) 580e41f4b71Sopenharmony_ci }.tabBar(new BottomTabBarStyle($r('sys.media.ohos_app_icon'), 'Pink')) 581e41f4b71Sopenharmony_ci .onWillShow(() => { 582e41f4b71Sopenharmony_ci console.info("Pink will show") 583e41f4b71Sopenharmony_ci }) 584e41f4b71Sopenharmony_ci .onWillHide(() => { 585e41f4b71Sopenharmony_ci console.info("Pink will hide") 586e41f4b71Sopenharmony_ci }) 587e41f4b71Sopenharmony_ci 588e41f4b71Sopenharmony_ci TabContent() { 589e41f4b71Sopenharmony_ci Column().width('100%').height('100%').backgroundColor(Color.Yellow) 590e41f4b71Sopenharmony_ci }.tabBar(new BottomTabBarStyle($r('sys.media.ohos_app_icon'), 'Yellow')) 591e41f4b71Sopenharmony_ci .onWillShow(() => { 592e41f4b71Sopenharmony_ci console.info("Yellow will show") 593e41f4b71Sopenharmony_ci }) 594e41f4b71Sopenharmony_ci .onWillHide(() => { 595e41f4b71Sopenharmony_ci console.info("Yellow will hide") 596e41f4b71Sopenharmony_ci }) 597e41f4b71Sopenharmony_ci 598e41f4b71Sopenharmony_ci TabContent() { 599e41f4b71Sopenharmony_ci Column().width('100%').height('100%').backgroundColor(Color.Blue) 600e41f4b71Sopenharmony_ci }.tabBar(new BottomTabBarStyle($r('sys.media.ohos_app_icon'), 'Blue')) 601e41f4b71Sopenharmony_ci .onWillShow(() => { 602e41f4b71Sopenharmony_ci console.info("Blue will show") 603e41f4b71Sopenharmony_ci }) 604e41f4b71Sopenharmony_ci .onWillHide(() => { 605e41f4b71Sopenharmony_ci console.info("Blue will hide") 606e41f4b71Sopenharmony_ci }) 607e41f4b71Sopenharmony_ci 608e41f4b71Sopenharmony_ci TabContent() { 609e41f4b71Sopenharmony_ci Column().width('100%').height('100%').backgroundColor(Color.Green) 610e41f4b71Sopenharmony_ci }.tabBar(new BottomTabBarStyle($r('sys.media.ohos_app_icon'), 'Green')) 611e41f4b71Sopenharmony_ci .onWillShow(() => { 612e41f4b71Sopenharmony_ci console.info("Green will show") 613e41f4b71Sopenharmony_ci }) 614e41f4b71Sopenharmony_ci .onWillHide(() => { 615e41f4b71Sopenharmony_ci console.info("Green will hide") 616e41f4b71Sopenharmony_ci }) 617e41f4b71Sopenharmony_ci } 618e41f4b71Sopenharmony_ci .vertical(false) 619e41f4b71Sopenharmony_ci .scrollable(true) 620e41f4b71Sopenharmony_ci .barMode(BarMode.Fixed) 621e41f4b71Sopenharmony_ci .onChange((index: number) => { 622e41f4b71Sopenharmony_ci console.info(index.toString()) 623e41f4b71Sopenharmony_ci }) 624e41f4b71Sopenharmony_ci .width('100%') 625e41f4b71Sopenharmony_ci .backgroundColor(0xF1F3F5) 626e41f4b71Sopenharmony_ci }.width('100%').height(200) 627e41f4b71Sopenharmony_ci Text ("Side Tab Style") 628e41f4b71Sopenharmony_ci Column() { 629e41f4b71Sopenharmony_ci Tabs({ barPosition: BarPosition.Start }) { 630e41f4b71Sopenharmony_ci TabContent() { 631e41f4b71Sopenharmony_ci Column().width('100%').height('100%').backgroundColor(Color.Pink) 632e41f4b71Sopenharmony_ci }.tabBar(new BottomTabBarStyle($r('sys.media.ohos_app_icon'), 'Pink')) 633e41f4b71Sopenharmony_ci .onWillShow(() => { 634e41f4b71Sopenharmony_ci console.info("Pink will show") 635e41f4b71Sopenharmony_ci }) 636e41f4b71Sopenharmony_ci .onWillHide(() => { 637e41f4b71Sopenharmony_ci console.info("Pink will hide") 638e41f4b71Sopenharmony_ci }) 639e41f4b71Sopenharmony_ci 640e41f4b71Sopenharmony_ci TabContent() { 641e41f4b71Sopenharmony_ci Column().width('100%').height('100%').backgroundColor(Color.Yellow) 642e41f4b71Sopenharmony_ci }.tabBar(new BottomTabBarStyle($r('sys.media.ohos_app_icon'), 'Yellow')) 643e41f4b71Sopenharmony_ci .onWillShow(() => { 644e41f4b71Sopenharmony_ci console.info("Yellow will show") 645e41f4b71Sopenharmony_ci }) 646e41f4b71Sopenharmony_ci .onWillHide(() => { 647e41f4b71Sopenharmony_ci console.info("Yellow will hide") 648e41f4b71Sopenharmony_ci }) 649e41f4b71Sopenharmony_ci 650e41f4b71Sopenharmony_ci TabContent() { 651e41f4b71Sopenharmony_ci Column().width('100%').height('100%').backgroundColor(Color.Blue) 652e41f4b71Sopenharmony_ci }.tabBar(new BottomTabBarStyle($r('sys.media.ohos_app_icon'), 'Blue')) 653e41f4b71Sopenharmony_ci .onWillShow(() => { 654e41f4b71Sopenharmony_ci console.info("Blue will show") 655e41f4b71Sopenharmony_ci }) 656e41f4b71Sopenharmony_ci .onWillHide(() => { 657e41f4b71Sopenharmony_ci console.info("Blue will hide") 658e41f4b71Sopenharmony_ci }) 659e41f4b71Sopenharmony_ci 660e41f4b71Sopenharmony_ci TabContent() { 661e41f4b71Sopenharmony_ci Column().width('100%').height('100%').backgroundColor(Color.Green) 662e41f4b71Sopenharmony_ci }.tabBar(new BottomTabBarStyle($r('sys.media.ohos_app_icon'), 'Green')) 663e41f4b71Sopenharmony_ci .onWillShow(() => { 664e41f4b71Sopenharmony_ci console.info("Green will show") 665e41f4b71Sopenharmony_ci }) 666e41f4b71Sopenharmony_ci .onWillHide(() => { 667e41f4b71Sopenharmony_ci console.info("Green will hide") 668e41f4b71Sopenharmony_ci }) 669e41f4b71Sopenharmony_ci } 670e41f4b71Sopenharmony_ci .vertical(true).scrollable(true).barMode(BarMode.Fixed) 671e41f4b71Sopenharmony_ci .onChange((index: number) => { 672e41f4b71Sopenharmony_ci console.info(index.toString()) 673e41f4b71Sopenharmony_ci }) 674e41f4b71Sopenharmony_ci .width('100%') 675e41f4b71Sopenharmony_ci .backgroundColor(0xF1F3F5) 676e41f4b71Sopenharmony_ci }.width('100%').height(400) 677e41f4b71Sopenharmony_ci } 678e41f4b71Sopenharmony_ci } 679e41f4b71Sopenharmony_ci} 680e41f4b71Sopenharmony_ci``` 681e41f4b71Sopenharmony_ci 682e41f4b71Sopenharmony_ci 683e41f4b71Sopenharmony_ci 684e41f4b71Sopenharmony_ci### Example 4 685e41f4b71Sopenharmony_ci 686e41f4b71Sopenharmony_ci```ts 687e41f4b71Sopenharmony_ci// xxx.ets 688e41f4b71Sopenharmony_ci@Entry 689e41f4b71Sopenharmony_ci@Component 690e41f4b71Sopenharmony_cistruct TabsAttr { 691e41f4b71Sopenharmony_ci private controller: TabsController = new TabsController() 692e41f4b71Sopenharmony_ci @State indicatorColor: Color = Color.Blue; 693e41f4b71Sopenharmony_ci @State indicatorWidth: number = 40; 694e41f4b71Sopenharmony_ci @State indicatorHeight: number = 10; 695e41f4b71Sopenharmony_ci @State indicatorBorderRadius: number = 5; 696e41f4b71Sopenharmony_ci @State indicatorSpace: number = 10; 697e41f4b71Sopenharmony_ci @State subTabBorderRadius: number = 20; 698e41f4b71Sopenharmony_ci @State selectedMode: SelectedMode = SelectedMode.INDICATOR; 699e41f4b71Sopenharmony_ci private colorFlag: boolean = true; 700e41f4b71Sopenharmony_ci private widthFlag: boolean = true; 701e41f4b71Sopenharmony_ci private heightFlag: boolean = true; 702e41f4b71Sopenharmony_ci private borderFlag: boolean = true; 703e41f4b71Sopenharmony_ci private spaceFlag: boolean = true; 704e41f4b71Sopenharmony_ci 705e41f4b71Sopenharmony_ci build() { 706e41f4b71Sopenharmony_ci Column() { 707e41f4b71Sopenharmony_ci Button ("Change Indicator Color").width ('100%').margin ({ bottom:'12vp' }) 708e41f4b71Sopenharmony_ci .onClick((event?: ClickEvent) => { 709e41f4b71Sopenharmony_ci // Animation configuration for the width and height attributes of the <Button> component 710e41f4b71Sopenharmony_ci if (this.colorFlag) { 711e41f4b71Sopenharmony_ci animateTo({ 712e41f4b71Sopenharmony_ci duration: 1000, // Animation duration. 713e41f4b71Sopenharmony_ci curve: Curve.Linear, // Animation curve. 714e41f4b71Sopenharmony_ci delay: 200, // Animation delay. 715e41f4b71Sopenharmony_ci iterations: 1, // Number of playback times. 716e41f4b71Sopenharmony_ci playMode: PlayMode.Normal, // Animation playback mode. 717e41f4b71Sopenharmony_ci onFinish: () => { 718e41f4b71Sopenharmony_ci console.info('play end') 719e41f4b71Sopenharmony_ci } 720e41f4b71Sopenharmony_ci }, () => { 721e41f4b71Sopenharmony_ci this.indicatorColor = Color.Red 722e41f4b71Sopenharmony_ci }) 723e41f4b71Sopenharmony_ci } else { 724e41f4b71Sopenharmony_ci animateTo({ 725e41f4b71Sopenharmony_ci duration: 1000, // Animation duration. 726e41f4b71Sopenharmony_ci curve: Curve.Linear, // Animation curve. 727e41f4b71Sopenharmony_ci delay: 200, // Animation delay. 728e41f4b71Sopenharmony_ci iterations: 1, // Number of playback times. 729e41f4b71Sopenharmony_ci playMode: PlayMode.Normal, // Animation playback mode. 730e41f4b71Sopenharmony_ci onFinish: () => { 731e41f4b71Sopenharmony_ci console.info('play end') 732e41f4b71Sopenharmony_ci } 733e41f4b71Sopenharmony_ci }, () => { 734e41f4b71Sopenharmony_ci this.indicatorColor = Color.Yellow 735e41f4b71Sopenharmony_ci }) 736e41f4b71Sopenharmony_ci } 737e41f4b71Sopenharmony_ci this.colorFlag = !this.colorFlag 738e41f4b71Sopenharmony_ci }) 739e41f4b71Sopenharmony_ci Button("Change Indicator Height").width('100%').margin({ bottom: '12vp' }) 740e41f4b71Sopenharmony_ci .onClick((event?: ClickEvent) => { 741e41f4b71Sopenharmony_ci // Animation configuration for the width and height attributes of the <Button> component 742e41f4b71Sopenharmony_ci if (this.heightFlag) { 743e41f4b71Sopenharmony_ci animateTo({ 744e41f4b71Sopenharmony_ci duration: 1000, // Animation duration. 745e41f4b71Sopenharmony_ci curve: Curve.Linear, // Animation curve. 746e41f4b71Sopenharmony_ci delay: 200, // Animation delay. 747e41f4b71Sopenharmony_ci iterations: 1, // Number of playback times. 748e41f4b71Sopenharmony_ci playMode: PlayMode.Normal, // Animation playback mode. 749e41f4b71Sopenharmony_ci onFinish: () => { 750e41f4b71Sopenharmony_ci console.info('play end') 751e41f4b71Sopenharmony_ci } 752e41f4b71Sopenharmony_ci }, () => { 753e41f4b71Sopenharmony_ci this.indicatorHeight = 20 754e41f4b71Sopenharmony_ci }) 755e41f4b71Sopenharmony_ci } else { 756e41f4b71Sopenharmony_ci animateTo({ 757e41f4b71Sopenharmony_ci duration: 1000, // Animation duration. 758e41f4b71Sopenharmony_ci curve: Curve.Linear, // Animation curve. 759e41f4b71Sopenharmony_ci delay: 200, // Animation delay. 760e41f4b71Sopenharmony_ci iterations: 1, // Number of playback times. 761e41f4b71Sopenharmony_ci playMode: PlayMode.Normal, // Animation playback mode. 762e41f4b71Sopenharmony_ci onFinish: () => { 763e41f4b71Sopenharmony_ci console.info('play end') 764e41f4b71Sopenharmony_ci } 765e41f4b71Sopenharmony_ci }, () => { 766e41f4b71Sopenharmony_ci this.indicatorHeight = 10 767e41f4b71Sopenharmony_ci }) 768e41f4b71Sopenharmony_ci } 769e41f4b71Sopenharmony_ci this.heightFlag = !this.heightFlag 770e41f4b71Sopenharmony_ci }) 771e41f4b71Sopenharmony_ci Button("Change Indicator Width").width('100%').margin({ bottom: '12vp' }) 772e41f4b71Sopenharmony_ci .onClick((event?: ClickEvent) => { 773e41f4b71Sopenharmony_ci // Animation configuration for the width and height attributes of the <Button> component 774e41f4b71Sopenharmony_ci if (this.widthFlag) { 775e41f4b71Sopenharmony_ci animateTo({ 776e41f4b71Sopenharmony_ci duration: 1000, // Animation duration. 777e41f4b71Sopenharmony_ci curve: Curve.Linear, // Animation curve. 778e41f4b71Sopenharmony_ci delay: 200, // Animation delay. 779e41f4b71Sopenharmony_ci iterations: 1, // Number of playback times. 780e41f4b71Sopenharmony_ci playMode: PlayMode.Normal, // Animation playback mode. 781e41f4b71Sopenharmony_ci onFinish: () => { 782e41f4b71Sopenharmony_ci console.info('play end') 783e41f4b71Sopenharmony_ci } 784e41f4b71Sopenharmony_ci }, () => { 785e41f4b71Sopenharmony_ci this.indicatorWidth = 30 786e41f4b71Sopenharmony_ci }) 787e41f4b71Sopenharmony_ci } else { 788e41f4b71Sopenharmony_ci animateTo({ 789e41f4b71Sopenharmony_ci duration: 1000, // Animation duration. 790e41f4b71Sopenharmony_ci curve: Curve.Linear, // Animation curve. 791e41f4b71Sopenharmony_ci delay: 200, // Animation delay. 792e41f4b71Sopenharmony_ci iterations: 1, // Number of playback times. 793e41f4b71Sopenharmony_ci playMode: PlayMode.Normal, // Animation playback mode. 794e41f4b71Sopenharmony_ci onFinish: () => { 795e41f4b71Sopenharmony_ci console.info('play end') 796e41f4b71Sopenharmony_ci } 797e41f4b71Sopenharmony_ci }, () => { 798e41f4b71Sopenharmony_ci this.indicatorWidth = 50 799e41f4b71Sopenharmony_ci }) 800e41f4b71Sopenharmony_ci } 801e41f4b71Sopenharmony_ci this.widthFlag = !this.widthFlag 802e41f4b71Sopenharmony_ci }) 803e41f4b71Sopenharmony_ci Button ("Change Indicator Corner Radius").width ('100%').margin ({ bottom:'12vp' }) 804e41f4b71Sopenharmony_ci .onClick((event?: ClickEvent) => { 805e41f4b71Sopenharmony_ci // Animation configuration for the width and height attributes of the <Button> component 806e41f4b71Sopenharmony_ci if (this.borderFlag) { 807e41f4b71Sopenharmony_ci animateTo({ 808e41f4b71Sopenharmony_ci duration: 1000, // Animation duration. 809e41f4b71Sopenharmony_ci curve: Curve.Linear, // Animation curve. 810e41f4b71Sopenharmony_ci delay: 200, // Animation delay. 811e41f4b71Sopenharmony_ci iterations: 1, // Number of playback times. 812e41f4b71Sopenharmony_ci playMode: PlayMode.Normal, // Animation playback mode. 813e41f4b71Sopenharmony_ci onFinish: () => { 814e41f4b71Sopenharmony_ci console.info('play end') 815e41f4b71Sopenharmony_ci } 816e41f4b71Sopenharmony_ci }, () => { 817e41f4b71Sopenharmony_ci this.indicatorBorderRadius = 0 818e41f4b71Sopenharmony_ci }) 819e41f4b71Sopenharmony_ci } else { 820e41f4b71Sopenharmony_ci animateTo({ 821e41f4b71Sopenharmony_ci duration: 1000, // Animation duration. 822e41f4b71Sopenharmony_ci curve: Curve.Linear, // Animation curve. 823e41f4b71Sopenharmony_ci delay: 200, // Animation delay. 824e41f4b71Sopenharmony_ci iterations: 1, // Number of playback times. 825e41f4b71Sopenharmony_ci playMode: PlayMode.Normal, // Animation playback mode. 826e41f4b71Sopenharmony_ci onFinish: () => { 827e41f4b71Sopenharmony_ci console.info('play end') 828e41f4b71Sopenharmony_ci } 829e41f4b71Sopenharmony_ci }, () => { 830e41f4b71Sopenharmony_ci this.indicatorBorderRadius = 5 831e41f4b71Sopenharmony_ci }) 832e41f4b71Sopenharmony_ci } 833e41f4b71Sopenharmony_ci this.borderFlag = !this.borderFlag 834e41f4b71Sopenharmony_ci }) 835e41f4b71Sopenharmony_ci Button ("Change Indicator Spacing").width ('100%').margin ({ bottom:'12vp' }) 836e41f4b71Sopenharmony_ci .onClick((event?: ClickEvent) => { 837e41f4b71Sopenharmony_ci // Animation configuration for the width and height attributes of the <Button> component 838e41f4b71Sopenharmony_ci if (this.spaceFlag) { 839e41f4b71Sopenharmony_ci animateTo({ 840e41f4b71Sopenharmony_ci duration: 1000, // Animation duration. 841e41f4b71Sopenharmony_ci curve: Curve.Linear, // Animation curve. 842e41f4b71Sopenharmony_ci delay: 200, // Animation delay. 843e41f4b71Sopenharmony_ci iterations: 1, // Number of playback times. 844e41f4b71Sopenharmony_ci playMode: PlayMode.Normal, // Animation playback mode. 845e41f4b71Sopenharmony_ci onFinish: () => { 846e41f4b71Sopenharmony_ci console.info('play end') 847e41f4b71Sopenharmony_ci } 848e41f4b71Sopenharmony_ci }, () => { 849e41f4b71Sopenharmony_ci this.indicatorSpace = 20 850e41f4b71Sopenharmony_ci }) 851e41f4b71Sopenharmony_ci } else { 852e41f4b71Sopenharmony_ci animateTo({ 853e41f4b71Sopenharmony_ci duration: 1000, // Animation duration. 854e41f4b71Sopenharmony_ci curve: Curve.Linear, // Animation curve. 855e41f4b71Sopenharmony_ci delay: 200, // Animation delay. 856e41f4b71Sopenharmony_ci iterations: 1, // Number of playback times. 857e41f4b71Sopenharmony_ci playMode: PlayMode.Normal, // Animation playback mode. 858e41f4b71Sopenharmony_ci onFinish: () => { 859e41f4b71Sopenharmony_ci console.info('play end') 860e41f4b71Sopenharmony_ci } 861e41f4b71Sopenharmony_ci }, () => { 862e41f4b71Sopenharmony_ci this.indicatorSpace = 10 863e41f4b71Sopenharmony_ci }) 864e41f4b71Sopenharmony_ci } 865e41f4b71Sopenharmony_ci this.spaceFlag = !this.spaceFlag 866e41f4b71Sopenharmony_ci }) 867e41f4b71Sopenharmony_ci Tabs({ barPosition: BarPosition.End, controller: this.controller }) { 868e41f4b71Sopenharmony_ci TabContent() { 869e41f4b71Sopenharmony_ci Column().width('100%').height('100%').backgroundColor(Color.Pink).borderRadius('12vp') 870e41f4b71Sopenharmony_ci }.tabBar(SubTabBarStyle.of('pink') 871e41f4b71Sopenharmony_ci .indicator({ 872e41f4b71Sopenharmony_ci color: this.indicatorColor, // Indicator color. 873e41f4b71Sopenharmony_ci height: this.indicatorHeight, // Indicator height. 874e41f4b71Sopenharmony_ci width: this.indicatorWidth, // Indicator width. 875e41f4b71Sopenharmony_ci borderRadius: this.indicatorBorderRadius, // Rounded corner radius of the indicator. 876e41f4b71Sopenharmony_ci marginTop: this.indicatorSpace // Spacing between the indicator and text. 877e41f4b71Sopenharmony_ci }) 878e41f4b71Sopenharmony_ci .selectedMode(this.selectedMode) 879e41f4b71Sopenharmony_ci .board({ borderRadius: this.subTabBorderRadius }) 880e41f4b71Sopenharmony_ci .labelStyle({}) 881e41f4b71Sopenharmony_ci ) 882e41f4b71Sopenharmony_ci 883e41f4b71Sopenharmony_ci TabContent() { 884e41f4b71Sopenharmony_ci Column().width('100%').height('100%').backgroundColor(Color.Yellow).borderRadius('12vp') 885e41f4b71Sopenharmony_ci }.tabBar('yellow') 886e41f4b71Sopenharmony_ci 887e41f4b71Sopenharmony_ci TabContent() { 888e41f4b71Sopenharmony_ci Column().width('100%').height('100%').backgroundColor(Color.Blue).borderRadius('12vp') 889e41f4b71Sopenharmony_ci }.tabBar('blue') 890e41f4b71Sopenharmony_ci 891e41f4b71Sopenharmony_ci TabContent() { 892e41f4b71Sopenharmony_ci Column().width('100%').height('100%').backgroundColor(Color.Green).borderRadius('12vp') 893e41f4b71Sopenharmony_ci }.tabBar('green') 894e41f4b71Sopenharmony_ci 895e41f4b71Sopenharmony_ci TabContent() { 896e41f4b71Sopenharmony_ci Column().width('100%').height('100%').backgroundColor(Color.Gray).borderRadius('12vp') 897e41f4b71Sopenharmony_ci }.tabBar('gray') 898e41f4b71Sopenharmony_ci 899e41f4b71Sopenharmony_ci TabContent() { 900e41f4b71Sopenharmony_ci Column().width('100%').height('100%').backgroundColor(Color.Orange).borderRadius('12vp') 901e41f4b71Sopenharmony_ci }.tabBar('orange') 902e41f4b71Sopenharmony_ci } 903e41f4b71Sopenharmony_ci .vertical(false) 904e41f4b71Sopenharmony_ci .scrollable(true) 905e41f4b71Sopenharmony_ci .barMode(BarMode.Scrollable) 906e41f4b71Sopenharmony_ci .barHeight(140) 907e41f4b71Sopenharmony_ci .animationDuration(400) 908e41f4b71Sopenharmony_ci .onChange((index: number) => { 909e41f4b71Sopenharmony_ci console.info(index.toString()) 910e41f4b71Sopenharmony_ci }) 911e41f4b71Sopenharmony_ci .backgroundColor(0xF5F5F5) 912e41f4b71Sopenharmony_ci .height(320) 913e41f4b71Sopenharmony_ci }.width('100%').height(250).padding({ top: '24vp', left: '24vp', right: '24vp' }) 914e41f4b71Sopenharmony_ci } 915e41f4b71Sopenharmony_ci} 916e41f4b71Sopenharmony_ci``` 917e41f4b71Sopenharmony_ci 918e41f4b71Sopenharmony_ci 919e41f4b71Sopenharmony_ci 920e41f4b71Sopenharmony_ci### Example 5 921e41f4b71Sopenharmony_ci 922e41f4b71Sopenharmony_ci```ts 923e41f4b71Sopenharmony_ci// xxx.ets 924e41f4b71Sopenharmony_ci@Entry 925e41f4b71Sopenharmony_ci@Component 926e41f4b71Sopenharmony_cistruct TabsTextOverflow { 927e41f4b71Sopenharmony_ci @State message: string = 'Hello World' 928e41f4b71Sopenharmony_ci private controller: TabsController = new TabsController() 929e41f4b71Sopenharmony_ci @State subTabOverflowOpaque: boolean = true; 930e41f4b71Sopenharmony_ci 931e41f4b71Sopenharmony_ci build() { 932e41f4b71Sopenharmony_ci Column() { 933e41f4b71Sopenharmony_ci Tabs({ barPosition: BarPosition.Start, controller: this.controller }) { 934e41f4b71Sopenharmony_ci TabContent() { 935e41f4b71Sopenharmony_ci Column() { 936e41f4b71Sopenharmony_ci Text('Use an ellipsis').fontSize(30).fontColor(0xFF000000) 937e41f4b71Sopenharmony_ci }.width('100%').height('100%').backgroundColor(Color.Pink) 938e41f4b71Sopenharmony_ci } 939e41f4b71Sopenharmony_ci .tabBar(SubTabBarStyle.of('Start [Use an ellipsis; Use an ellipsis] End') 940e41f4b71Sopenharmony_ci .labelStyle({ 941e41f4b71Sopenharmony_ci overflow: TextOverflow.Ellipsis, 942e41f4b71Sopenharmony_ci maxLines: 1, 943e41f4b71Sopenharmony_ci minFontSize: 10, 944e41f4b71Sopenharmony_ci heightAdaptivePolicy: TextHeightAdaptivePolicy.MAX_LINES_FIRST, 945e41f4b71Sopenharmony_ci font: { size: 20 } 946e41f4b71Sopenharmony_ci })) 947e41f4b71Sopenharmony_ci 948e41f4b71Sopenharmony_ci TabContent() { 949e41f4b71Sopenharmony_ci Column() { 950e41f4b71Sopenharmony_ci Text('Scale down and then clip').fontSize(30).fontColor(0xFF000000) 951e41f4b71Sopenharmony_ci }.width('100%').height('100%').backgroundColor(Color.Pink) 952e41f4b71Sopenharmony_ci } 953e41f4b71Sopenharmony_ci .tabBar(SubTabBarStyle.of('Start [Scale down and then clip; Scale down and then clip] End') 954e41f4b71Sopenharmony_ci .labelStyle({ 955e41f4b71Sopenharmony_ci overflow: TextOverflow.Clip, 956e41f4b71Sopenharmony_ci maxLines: 1, 957e41f4b71Sopenharmony_ci minFontSize: 15, 958e41f4b71Sopenharmony_ci maxFontSize: 15, 959e41f4b71Sopenharmony_ci heightAdaptivePolicy: TextHeightAdaptivePolicy.MIN_FONT_SIZE_FIRST, 960e41f4b71Sopenharmony_ci font: { size: 20 } 961e41f4b71Sopenharmony_ci })) 962e41f4b71Sopenharmony_ci 963e41f4b71Sopenharmony_ci TabContent() { 964e41f4b71Sopenharmony_ci Column() { 965e41f4b71Sopenharmony_ci Text('Scale down, start a new line, and then clip').fontSize(30).fontColor(0xFF000000) 966e41f4b71Sopenharmony_ci }.width('100%').height('100%').backgroundColor(Color.Pink) 967e41f4b71Sopenharmony_ci } 968e41f4b71Sopenharmony_ci .tabBar(SubTabBarStyle.of('Start [Scale down, start a new line, and then clip; Scale down, start a new line, and then clip] End') 969e41f4b71Sopenharmony_ci .labelStyle({ 970e41f4b71Sopenharmony_ci overflow: TextOverflow.Clip, 971e41f4b71Sopenharmony_ci maxLines: 2, 972e41f4b71Sopenharmony_ci minFontSize: 15, 973e41f4b71Sopenharmony_ci maxFontSize: 15, 974e41f4b71Sopenharmony_ci heightAdaptivePolicy: TextHeightAdaptivePolicy.MIN_FONT_SIZE_FIRST, 975e41f4b71Sopenharmony_ci font: { size: 20 } 976e41f4b71Sopenharmony_ci })) 977e41f4b71Sopenharmony_ci 978e41f4b71Sopenharmony_ci TabContent() { 979e41f4b71Sopenharmony_ci Column() { 980e41f4b71Sopenharmony_ci Text('Start a new line').fontSize(30).fontColor(0xFF000000) 981e41f4b71Sopenharmony_ci } 982e41f4b71Sopenharmony_ci .width('100%').height('100%').backgroundColor(Color.Pink) 983e41f4b71Sopenharmony_ci }.tabBar(SubTabBarStyle.of('Start [Start a new line; Start a new line; Start a new line; Start a new line; Start a new line] End') 984e41f4b71Sopenharmony_ci .labelStyle({ 985e41f4b71Sopenharmony_ci overflow: TextOverflow.Clip, 986e41f4b71Sopenharmony_ci maxLines: 10, 987e41f4b71Sopenharmony_ci minFontSize: 10, 988e41f4b71Sopenharmony_ci heightAdaptivePolicy: TextHeightAdaptivePolicy.MAX_LINES_FIRST, 989e41f4b71Sopenharmony_ci font: { size: 20 } 990e41f4b71Sopenharmony_ci })) 991e41f4b71Sopenharmony_ci } 992e41f4b71Sopenharmony_ci .vertical(true).scrollable(true) 993e41f4b71Sopenharmony_ci .barMode(BarMode.Fixed) 994e41f4b71Sopenharmony_ci .barHeight(720) 995e41f4b71Sopenharmony_ci .barWidth(200).animationDuration(400) 996e41f4b71Sopenharmony_ci .onChange((index: number) => { 997e41f4b71Sopenharmony_ci console.info(index.toString()) 998e41f4b71Sopenharmony_ci }) 999e41f4b71Sopenharmony_ci .height('100%').width('100%') 1000e41f4b71Sopenharmony_ci } 1001e41f4b71Sopenharmony_ci .height('100%') 1002e41f4b71Sopenharmony_ci } 1003e41f4b71Sopenharmony_ci} 1004e41f4b71Sopenharmony_ci``` 1005e41f4b71Sopenharmony_ci 1006e41f4b71Sopenharmony_ci 1007e41f4b71Sopenharmony_ci 1008e41f4b71Sopenharmony_ci### Example 6 1009e41f4b71Sopenharmony_ci 1010e41f4b71Sopenharmony_ci```ts 1011e41f4b71Sopenharmony_ci// xxx.ets 1012e41f4b71Sopenharmony_ci@Entry 1013e41f4b71Sopenharmony_ci@Component 1014e41f4b71Sopenharmony_cistruct TabContentExample6 { 1015e41f4b71Sopenharmony_ci private controller: TabsController = new TabsController() 1016e41f4b71Sopenharmony_ci @State text: string = "2" 1017e41f4b71Sopenharmony_ci @State tabPadding: number = 0; 1018e41f4b71Sopenharmony_ci @State symmetricExtensible: boolean = false; 1019e41f4b71Sopenharmony_ci @State layoutMode: LayoutMode = LayoutMode.VERTICAL; 1020e41f4b71Sopenharmony_ci @State verticalAlign: VerticalAlign = VerticalAlign.Center; 1021e41f4b71Sopenharmony_ci 1022e41f4b71Sopenharmony_ci build() { 1023e41f4b71Sopenharmony_ci Column() { 1024e41f4b71Sopenharmony_ci Row() { 1025e41f4b71Sopenharmony_ci Button("padding+10 " + this.tabPadding) 1026e41f4b71Sopenharmony_ci .width('47%') 1027e41f4b71Sopenharmony_ci .height(50) 1028e41f4b71Sopenharmony_ci .margin({ top: 5 }) 1029e41f4b71Sopenharmony_ci .onClick((event?: ClickEvent) => { 1030e41f4b71Sopenharmony_ci this.tabPadding += 10 1031e41f4b71Sopenharmony_ci }) 1032e41f4b71Sopenharmony_ci .margin({ right: '6%', bottom: '12vp' }) 1033e41f4b71Sopenharmony_ci Button("padding-10 " + this.tabPadding) 1034e41f4b71Sopenharmony_ci .width('47%') 1035e41f4b71Sopenharmony_ci .height(50) 1036e41f4b71Sopenharmony_ci .margin({ top: 5 }) 1037e41f4b71Sopenharmony_ci .onClick((event?: ClickEvent) => { 1038e41f4b71Sopenharmony_ci this.tabPadding -= 10 1039e41f4b71Sopenharmony_ci }) 1040e41f4b71Sopenharmony_ci .margin({ bottom: '12vp' }) 1041e41f4b71Sopenharmony_ci } 1042e41f4b71Sopenharmony_ci 1043e41f4b71Sopenharmony_ci Row() { 1044e41f4b71Sopenharmony_ci Button ("Add Text") 1045e41f4b71Sopenharmony_ci .width('47%') 1046e41f4b71Sopenharmony_ci .height(50) 1047e41f4b71Sopenharmony_ci .margin({ top: 5 }) 1048e41f4b71Sopenharmony_ci .onClick((event?: ClickEvent) => { 1049e41f4b71Sopenharmony_ci this.text += 'Add Text' 1050e41f4b71Sopenharmony_ci }) 1051e41f4b71Sopenharmony_ci .margin({ right: '6%', bottom: '12vp' }) 1052e41f4b71Sopenharmony_ci Button ("Reset Text") 1053e41f4b71Sopenharmony_ci .width('47%') 1054e41f4b71Sopenharmony_ci .height(50) 1055e41f4b71Sopenharmony_ci .margin({ top: 5 }) 1056e41f4b71Sopenharmony_ci .onClick((event?: ClickEvent) => { 1057e41f4b71Sopenharmony_ci this.text = "2" 1058e41f4b71Sopenharmony_ci }) 1059e41f4b71Sopenharmony_ci .margin({ bottom: '12vp' }) 1060e41f4b71Sopenharmony_ci } 1061e41f4b71Sopenharmony_ci 1062e41f4b71Sopenharmony_ci Row() { 1063e41f4b71Sopenharmony_ci Button ("Set SymmetricExtensible to " + this.symmetricExtensible) 1064e41f4b71Sopenharmony_ci .width('100%') 1065e41f4b71Sopenharmony_ci .height(50) 1066e41f4b71Sopenharmony_ci .margin({ top: 5 }) 1067e41f4b71Sopenharmony_ci .onClick((event?: ClickEvent) => { 1068e41f4b71Sopenharmony_ci this.symmetricExtensible = !this.symmetricExtensible 1069e41f4b71Sopenharmony_ci }) 1070e41f4b71Sopenharmony_ci .margin({ bottom: '12vp' }) 1071e41f4b71Sopenharmony_ci } 1072e41f4b71Sopenharmony_ci 1073e41f4b71Sopenharmony_ci Row() { 1074e41f4b71Sopenharmony_ci Button ("Vertical Layout") 1075e41f4b71Sopenharmony_ci .width('47%') 1076e41f4b71Sopenharmony_ci .height(50) 1077e41f4b71Sopenharmony_ci .margin({ top: 5 }) 1078e41f4b71Sopenharmony_ci .onClick((event?: ClickEvent) => { 1079e41f4b71Sopenharmony_ci this.layoutMode = LayoutMode.VERTICAL; 1080e41f4b71Sopenharmony_ci }) 1081e41f4b71Sopenharmony_ci .margin({ right: '6%', bottom: '12vp' }) 1082e41f4b71Sopenharmony_ci Button ("Horizontal Layout") 1083e41f4b71Sopenharmony_ci .width('47%') 1084e41f4b71Sopenharmony_ci .height(50) 1085e41f4b71Sopenharmony_ci .margin({ top: 5 }) 1086e41f4b71Sopenharmony_ci .onClick((event?: ClickEvent) => { 1087e41f4b71Sopenharmony_ci this.layoutMode = LayoutMode.HORIZONTAL; 1088e41f4b71Sopenharmony_ci }) 1089e41f4b71Sopenharmony_ci .margin({ bottom: '12vp' }) 1090e41f4b71Sopenharmony_ci } 1091e41f4b71Sopenharmony_ci 1092e41f4b71Sopenharmony_ci Row() { 1093e41f4b71Sopenharmony_ci Button ("VerticalAlign.Top") 1094e41f4b71Sopenharmony_ci .width('100%') 1095e41f4b71Sopenharmony_ci .height(50) 1096e41f4b71Sopenharmony_ci .margin({ top: 5 }) 1097e41f4b71Sopenharmony_ci .onClick((event?: ClickEvent) => { 1098e41f4b71Sopenharmony_ci this.verticalAlign = VerticalAlign.Top; 1099e41f4b71Sopenharmony_ci }) 1100e41f4b71Sopenharmony_ci .margin({ bottom: '12vp' }) 1101e41f4b71Sopenharmony_ci } 1102e41f4b71Sopenharmony_ci 1103e41f4b71Sopenharmony_ci Row() { 1104e41f4b71Sopenharmony_ci Button ("VerticalAlign.Center") 1105e41f4b71Sopenharmony_ci .width('100%') 1106e41f4b71Sopenharmony_ci .height(50) 1107e41f4b71Sopenharmony_ci .margin({ top: 5 }) 1108e41f4b71Sopenharmony_ci .onClick((event?: ClickEvent) => { 1109e41f4b71Sopenharmony_ci this.verticalAlign = VerticalAlign.Center; 1110e41f4b71Sopenharmony_ci }) 1111e41f4b71Sopenharmony_ci .margin({ bottom: '12vp' }) 1112e41f4b71Sopenharmony_ci } 1113e41f4b71Sopenharmony_ci 1114e41f4b71Sopenharmony_ci Row() { 1115e41f4b71Sopenharmony_ci Button ("VerticalAlign.Bottom") 1116e41f4b71Sopenharmony_ci .width('100%') 1117e41f4b71Sopenharmony_ci .height(50) 1118e41f4b71Sopenharmony_ci .margin({ top: 5 }) 1119e41f4b71Sopenharmony_ci .onClick((event?: ClickEvent) => { 1120e41f4b71Sopenharmony_ci this.verticalAlign = VerticalAlign.Bottom; 1121e41f4b71Sopenharmony_ci }) 1122e41f4b71Sopenharmony_ci .margin({ bottom: '12vp' }) 1123e41f4b71Sopenharmony_ci } 1124e41f4b71Sopenharmony_ci 1125e41f4b71Sopenharmony_ci 1126e41f4b71Sopenharmony_ci Tabs({ barPosition: BarPosition.End, controller: this.controller }) { 1127e41f4b71Sopenharmony_ci TabContent() { 1128e41f4b71Sopenharmony_ci Column().width('100%').height('100%').backgroundColor(Color.Pink) 1129e41f4b71Sopenharmony_ci }.tabBar(BottomTabBarStyle.of($r("sys.media.ohos_app_icon"), "1")) 1130e41f4b71Sopenharmony_ci 1131e41f4b71Sopenharmony_ci TabContent() { 1132e41f4b71Sopenharmony_ci Column().width('100%').height('100%').backgroundColor(Color.Green) 1133e41f4b71Sopenharmony_ci }.tabBar(BottomTabBarStyle.of($r("sys.media.ohos_app_icon"), this.text) 1134e41f4b71Sopenharmony_ci .padding(this.tabPadding) 1135e41f4b71Sopenharmony_ci .verticalAlign(this.verticalAlign) 1136e41f4b71Sopenharmony_ci .layoutMode(this.layoutMode) 1137e41f4b71Sopenharmony_ci .symmetricExtensible(this.symmetricExtensible)) 1138e41f4b71Sopenharmony_ci 1139e41f4b71Sopenharmony_ci TabContent() { 1140e41f4b71Sopenharmony_ci Column().width('100%').height('100%').backgroundColor(Color.Blue) 1141e41f4b71Sopenharmony_ci }.tabBar(BottomTabBarStyle.of($r("sys.media.ohos_app_icon"), "3")) 1142e41f4b71Sopenharmony_ci } 1143e41f4b71Sopenharmony_ci .animationDuration(300) 1144e41f4b71Sopenharmony_ci .height('60%') 1145e41f4b71Sopenharmony_ci .backgroundColor(0xf1f3f5) 1146e41f4b71Sopenharmony_ci .barMode(BarMode.Fixed) 1147e41f4b71Sopenharmony_ci } 1148e41f4b71Sopenharmony_ci .width('100%') 1149e41f4b71Sopenharmony_ci .height(500) 1150e41f4b71Sopenharmony_ci .margin({ top: 5 }) 1151e41f4b71Sopenharmony_ci .padding('24vp') 1152e41f4b71Sopenharmony_ci } 1153e41f4b71Sopenharmony_ci} 1154e41f4b71Sopenharmony_ci``` 1155e41f4b71Sopenharmony_ci 1156e41f4b71Sopenharmony_ci 1157e41f4b71Sopenharmony_ci 1158e41f4b71Sopenharmony_ci### Example 7 1159e41f4b71Sopenharmony_ci 1160e41f4b71Sopenharmony_ciIn this example, **unselectedColor** and **selectedColor** in **labelStyle** are used to change the font color of the bottom tab and subtab. 1161e41f4b71Sopenharmony_ci**unselectedColor** and **selectedColor** in **iconStyle** are used to change the icon color of the bottom tab. 1162e41f4b71Sopenharmony_ci 1163e41f4b71Sopenharmony_ci```ts 1164e41f4b71Sopenharmony_ci// xxx.ets 1165e41f4b71Sopenharmony_ci@Entry 1166e41f4b71Sopenharmony_ci@Component 1167e41f4b71Sopenharmony_cistruct TabBarStyleExample { 1168e41f4b71Sopenharmony_ci build() { 1169e41f4b71Sopenharmony_ci Column({ space: 5 }) { 1170e41f4b71Sopenharmony_ci Text ("Subtab Style") 1171e41f4b71Sopenharmony_ci Column() { 1172e41f4b71Sopenharmony_ci Tabs({ barPosition: BarPosition.Start }) { 1173e41f4b71Sopenharmony_ci TabContent() { 1174e41f4b71Sopenharmony_ci Column().width('100%').height('100%').backgroundColor(Color.Pink) 1175e41f4b71Sopenharmony_ci }.tabBar(new SubTabBarStyle('Pink') 1176e41f4b71Sopenharmony_ci .labelStyle({ unselectedColor: Color.Red, selectedColor: Color.Green })) 1177e41f4b71Sopenharmony_ci 1178e41f4b71Sopenharmony_ci TabContent() { 1179e41f4b71Sopenharmony_ci Column().width('100%').height('100%').backgroundColor(Color.Yellow) 1180e41f4b71Sopenharmony_ci }.tabBar(new SubTabBarStyle('Yellow') 1181e41f4b71Sopenharmony_ci .labelStyle({ unselectedColor: Color.Red, selectedColor: Color.Green })) 1182e41f4b71Sopenharmony_ci 1183e41f4b71Sopenharmony_ci TabContent() { 1184e41f4b71Sopenharmony_ci Column().width('100%').height('100%').backgroundColor(Color.Blue) 1185e41f4b71Sopenharmony_ci }.tabBar(new SubTabBarStyle('Blue') 1186e41f4b71Sopenharmony_ci .labelStyle({ unselectedColor: Color.Red, selectedColor: Color.Green })) 1187e41f4b71Sopenharmony_ci 1188e41f4b71Sopenharmony_ci TabContent() { 1189e41f4b71Sopenharmony_ci Column().width('100%').height('100%').backgroundColor(Color.Green) 1190e41f4b71Sopenharmony_ci }.tabBar(new SubTabBarStyle('Green') 1191e41f4b71Sopenharmony_ci .labelStyle({ unselectedColor: Color.Red, selectedColor: Color.Green }) 1192e41f4b71Sopenharmony_ci ) 1193e41f4b71Sopenharmony_ci } 1194e41f4b71Sopenharmony_ci .vertical(false) 1195e41f4b71Sopenharmony_ci .scrollable(true) 1196e41f4b71Sopenharmony_ci .barMode(BarMode.Fixed) 1197e41f4b71Sopenharmony_ci .onChange((index: number) => { 1198e41f4b71Sopenharmony_ci console.info(index.toString()) 1199e41f4b71Sopenharmony_ci }) 1200e41f4b71Sopenharmony_ci .width('100%') 1201e41f4b71Sopenharmony_ci .backgroundColor(0xF1F3F5) 1202e41f4b71Sopenharmony_ci }.width('100%').height(200) 1203e41f4b71Sopenharmony_ci 1204e41f4b71Sopenharmony_ci Text ("Bottom Tab Style") 1205e41f4b71Sopenharmony_ci Column() { 1206e41f4b71Sopenharmony_ci Tabs({ barPosition: BarPosition.End }) { 1207e41f4b71Sopenharmony_ci TabContent() { 1208e41f4b71Sopenharmony_ci Column().width('100%').height('100%').backgroundColor(Color.Pink) 1209e41f4b71Sopenharmony_ci } 1210e41f4b71Sopenharmony_ci .tabBar(new BottomTabBarStyle('/common/public_icon_off.svg', 'pink') 1211e41f4b71Sopenharmony_ci .labelStyle({ unselectedColor: Color.Red, selectedColor: Color.Green }) 1212e41f4b71Sopenharmony_ci .iconStyle({ unselectedColor: Color.Red, selectedColor: Color.Green }) 1213e41f4b71Sopenharmony_ci ) 1214e41f4b71Sopenharmony_ci 1215e41f4b71Sopenharmony_ci TabContent() { 1216e41f4b71Sopenharmony_ci Column().width('100%').height('100%').backgroundColor(Color.Yellow) 1217e41f4b71Sopenharmony_ci }.tabBar(new BottomTabBarStyle('/common/public_icon_off.svg', 'Yellow') 1218e41f4b71Sopenharmony_ci .labelStyle({ unselectedColor: Color.Red, selectedColor: Color.Green }) 1219e41f4b71Sopenharmony_ci .iconStyle({ unselectedColor: Color.Red, selectedColor: Color.Green }) 1220e41f4b71Sopenharmony_ci ) 1221e41f4b71Sopenharmony_ci 1222e41f4b71Sopenharmony_ci TabContent() { 1223e41f4b71Sopenharmony_ci Column().width('100%').height('100%').backgroundColor(Color.Blue) 1224e41f4b71Sopenharmony_ci }.tabBar(new BottomTabBarStyle('/common/public_icon_off.svg', 'Blue') 1225e41f4b71Sopenharmony_ci .labelStyle({ unselectedColor: Color.Red, selectedColor: Color.Green }) 1226e41f4b71Sopenharmony_ci .iconStyle({ unselectedColor: Color.Red, selectedColor: Color.Green }) 1227e41f4b71Sopenharmony_ci ) 1228e41f4b71Sopenharmony_ci 1229e41f4b71Sopenharmony_ci TabContent() { 1230e41f4b71Sopenharmony_ci Column().width('100%').height('100%').backgroundColor(Color.Green) 1231e41f4b71Sopenharmony_ci }.tabBar(new BottomTabBarStyle('/common/public_icon_off.svg', 'Green') 1232e41f4b71Sopenharmony_ci .labelStyle({ unselectedColor: Color.Red, selectedColor: Color.Green }) 1233e41f4b71Sopenharmony_ci .iconStyle({ unselectedColor: Color.Red, selectedColor: Color.Green }) 1234e41f4b71Sopenharmony_ci ) 1235e41f4b71Sopenharmony_ci } 1236e41f4b71Sopenharmony_ci .vertical(false) 1237e41f4b71Sopenharmony_ci .scrollable(true) 1238e41f4b71Sopenharmony_ci .barMode(BarMode.Fixed) 1239e41f4b71Sopenharmony_ci .onChange((index: number) => { 1240e41f4b71Sopenharmony_ci console.info(index.toString()) 1241e41f4b71Sopenharmony_ci }) 1242e41f4b71Sopenharmony_ci .width('100%') 1243e41f4b71Sopenharmony_ci .backgroundColor(0xF1F3F5) 1244e41f4b71Sopenharmony_ci }.width('100%').height(200) 1245e41f4b71Sopenharmony_ci } 1246e41f4b71Sopenharmony_ci } 1247e41f4b71Sopenharmony_ci} 1248e41f4b71Sopenharmony_ci``` 1249e41f4b71Sopenharmony_ci 1250e41f4b71Sopenharmony_ci 1251e41f4b71Sopenharmony_ci 1252e41f4b71Sopenharmony_ci### Example 8 1253e41f4b71Sopenharmony_ciThis example sets **SubTabBarStyle** through **ComponentContent**. 1254e41f4b71Sopenharmony_ci```ts 1255e41f4b71Sopenharmony_ci// xxx.ets 1256e41f4b71Sopenharmony_ciimport { ComponentContent, UIContext } from "@kit.ArkUI" 1257e41f4b71Sopenharmony_ci 1258e41f4b71Sopenharmony_ciclass Params { 1259e41f4b71Sopenharmony_ci text: string = "" 1260e41f4b71Sopenharmony_ci 1261e41f4b71Sopenharmony_ci constructor(text: string) { 1262e41f4b71Sopenharmony_ci this.text = text; 1263e41f4b71Sopenharmony_ci } 1264e41f4b71Sopenharmony_ci} 1265e41f4b71Sopenharmony_ci 1266e41f4b71Sopenharmony_ci@Builder 1267e41f4b71Sopenharmony_cifunction buildText(params: Params) { 1268e41f4b71Sopenharmony_ci Column() { 1269e41f4b71Sopenharmony_ci Text(params.text) 1270e41f4b71Sopenharmony_ci .fontSize(20) 1271e41f4b71Sopenharmony_ci .fontWeight(FontWeight.Bold) 1272e41f4b71Sopenharmony_ci .margin(20) 1273e41f4b71Sopenharmony_ci } 1274e41f4b71Sopenharmony_ci} 1275e41f4b71Sopenharmony_ci 1276e41f4b71Sopenharmony_ci@Entry 1277e41f4b71Sopenharmony_ci@Component 1278e41f4b71Sopenharmony_cistruct Index { 1279e41f4b71Sopenharmony_ci @State message1: string = "tabBar1" 1280e41f4b71Sopenharmony_ci @State message2: string = "tabBar2" 1281e41f4b71Sopenharmony_ci context: UIContext = this.getUIContext() 1282e41f4b71Sopenharmony_ci private count1 = 0; 1283e41f4b71Sopenharmony_ci private count2 = 0; 1284e41f4b71Sopenharmony_ci private controller: TabsController = new TabsController(); 1285e41f4b71Sopenharmony_ci tabBar1: ComponentContent<Params> = new ComponentContent<Params>(this.context, wrapBuilder<[Params]>(buildText), new Params(this.message1)); 1286e41f4b71Sopenharmony_ci tabBar2: ComponentContent<Params> = new ComponentContent<Params>(this.context, wrapBuilder<[Params]>(buildText), new Params(this.message2)); 1287e41f4b71Sopenharmony_ci 1288e41f4b71Sopenharmony_ci build() { 1289e41f4b71Sopenharmony_ci Row() { 1290e41f4b71Sopenharmony_ci Column() { 1291e41f4b71Sopenharmony_ci Button("Update tabBar1").width('90%').margin(20) 1292e41f4b71Sopenharmony_ci .onClick((event?: ClickEvent) => { 1293e41f4b71Sopenharmony_ci this.count1 += 1; 1294e41f4b71Sopenharmony_ci const message1 = "Update 1_" + this.count1.toString(); 1295e41f4b71Sopenharmony_ci this.tabBar1.update(new Params(message1)); 1296e41f4b71Sopenharmony_ci }) 1297e41f4b71Sopenharmony_ci Button("Update tabBar2").width('90%').margin(20) 1298e41f4b71Sopenharmony_ci .onClick((event?: ClickEvent) => { 1299e41f4b71Sopenharmony_ci this.count2 += 1; 1300e41f4b71Sopenharmony_ci const message2 = "Update 2_" + this.count2.toString(); 1301e41f4b71Sopenharmony_ci this.tabBar2.update(new Params(message2)); 1302e41f4b71Sopenharmony_ci }) 1303e41f4b71Sopenharmony_ci Tabs({ barPosition: BarPosition.Start, controller: this.controller }) { 1304e41f4b71Sopenharmony_ci TabContent() { 1305e41f4b71Sopenharmony_ci Column().width('100%').height('100%').backgroundColor(Color.Pink).borderRadius('12vp') 1306e41f4b71Sopenharmony_ci }.tabBar(new SubTabBarStyle(this.tabBar1)) 1307e41f4b71Sopenharmony_ci TabContent() { 1308e41f4b71Sopenharmony_ci Column().width('100%').height('100%').backgroundColor(Color.Blue).borderRadius('12vp') 1309e41f4b71Sopenharmony_ci }.tabBar(SubTabBarStyle.of(this.tabBar2)) 1310e41f4b71Sopenharmony_ci } 1311e41f4b71Sopenharmony_ci .vertical(false) 1312e41f4b71Sopenharmony_ci .barWidth(414) 1313e41f4b71Sopenharmony_ci .barHeight(96) 1314e41f4b71Sopenharmony_ci .width(414) 1315e41f4b71Sopenharmony_ci .height(414) 1316e41f4b71Sopenharmony_ci .backgroundColor('#F1F3F5') 1317e41f4b71Sopenharmony_ci .margin({ top: 20 }) 1318e41f4b71Sopenharmony_ci } 1319e41f4b71Sopenharmony_ci .width('100%') 1320e41f4b71Sopenharmony_ci .height('100%') 1321e41f4b71Sopenharmony_ci } 1322e41f4b71Sopenharmony_ci .height('100%') 1323e41f4b71Sopenharmony_ci } 1324e41f4b71Sopenharmony_ci} 1325e41f4b71Sopenharmony_ci``` 1326e41f4b71Sopenharmony_ci 1327e41f4b71Sopenharmony_ci 1328e41f4b71Sopenharmony_ci 1329e41f4b71Sopenharmony_ci### Example 9 1330e41f4b71Sopenharmony_ciIn this example, a symbol icon is passed in to **BottomTabBarStyle**. 1331e41f4b71Sopenharmony_ci```ts 1332e41f4b71Sopenharmony_ci// xxx.ets 1333e41f4b71Sopenharmony_ciimport { SymbolGlyphModifier } from '@kit.ArkUI' 1334e41f4b71Sopenharmony_ci 1335e41f4b71Sopenharmony_ci@Entry 1336e41f4b71Sopenharmony_ci@Component 1337e41f4b71Sopenharmony_cistruct Index { 1338e41f4b71Sopenharmony_ci @State symbolModifier1: SymbolGlyphModifier = new SymbolGlyphModifier($r('sys.symbol.ohos_wifi')); 1339e41f4b71Sopenharmony_ci @State symbolModifier2: SymbolGlyphModifier = new SymbolGlyphModifier($r('sys.symbol.ellipsis_bubble')); 1340e41f4b71Sopenharmony_ci @State symbolModifier3: SymbolGlyphModifier = new SymbolGlyphModifier($r('sys.symbol.dot_video')); 1341e41f4b71Sopenharmony_ci @State symbolModifier4: SymbolGlyphModifier = new SymbolGlyphModifier($r('sys.symbol.exposure')); 1342e41f4b71Sopenharmony_ci build() { 1343e41f4b71Sopenharmony_ci Column({space: 5}) { 1344e41f4b71Sopenharmony_ci Text ("Bottom Tab Style") 1345e41f4b71Sopenharmony_ci Column(){ 1346e41f4b71Sopenharmony_ci Tabs({barPosition: BarPosition.End}) { 1347e41f4b71Sopenharmony_ci TabContent() { 1348e41f4b71Sopenharmony_ci Column().width('100%').height('100%').backgroundColor(Color.Pink) 1349e41f4b71Sopenharmony_ci }.tabBar(new BottomTabBarStyle({ 1350e41f4b71Sopenharmony_ci normal: this.symbolModifier1, 1351e41f4b71Sopenharmony_ci }, 'Pink')) 1352e41f4b71Sopenharmony_ci .onWillShow(() => { 1353e41f4b71Sopenharmony_ci console.info("Pink will show") 1354e41f4b71Sopenharmony_ci }) 1355e41f4b71Sopenharmony_ci .onWillHide(() => { 1356e41f4b71Sopenharmony_ci console.info("Pink will hide") 1357e41f4b71Sopenharmony_ci }) 1358e41f4b71Sopenharmony_ci 1359e41f4b71Sopenharmony_ci TabContent() { 1360e41f4b71Sopenharmony_ci Column().width('100%').height('100%').backgroundColor(Color.Orange) 1361e41f4b71Sopenharmony_ci }.tabBar(new BottomTabBarStyle({ 1362e41f4b71Sopenharmony_ci normal: this.symbolModifier2, 1363e41f4b71Sopenharmony_ci }, 'Orange')) 1364e41f4b71Sopenharmony_ci .onWillShow(() => { 1365e41f4b71Sopenharmony_ci console.info("Orange will show") 1366e41f4b71Sopenharmony_ci }) 1367e41f4b71Sopenharmony_ci .onWillHide(() => { 1368e41f4b71Sopenharmony_ci console.info("Orange will hide") 1369e41f4b71Sopenharmony_ci }) 1370e41f4b71Sopenharmony_ci 1371e41f4b71Sopenharmony_ci TabContent() { 1372e41f4b71Sopenharmony_ci Column().width('100%').height('100%').backgroundColor(Color.Blue) 1373e41f4b71Sopenharmony_ci }.tabBar(new BottomTabBarStyle({ 1374e41f4b71Sopenharmony_ci normal: this.symbolModifier3, 1375e41f4b71Sopenharmony_ci }, 'Blue')) 1376e41f4b71Sopenharmony_ci .onWillShow(() => { 1377e41f4b71Sopenharmony_ci console.info("Blue will show") 1378e41f4b71Sopenharmony_ci }) 1379e41f4b71Sopenharmony_ci .onWillHide(() => { 1380e41f4b71Sopenharmony_ci console.info("Blue will hide") 1381e41f4b71Sopenharmony_ci }) 1382e41f4b71Sopenharmony_ci 1383e41f4b71Sopenharmony_ci TabContent() { 1384e41f4b71Sopenharmony_ci Column().width('100%').height('100%').backgroundColor(Color.Green) 1385e41f4b71Sopenharmony_ci }.tabBar(new BottomTabBarStyle({ 1386e41f4b71Sopenharmony_ci normal: this.symbolModifier4, 1387e41f4b71Sopenharmony_ci }, 'Green')) 1388e41f4b71Sopenharmony_ci .onWillShow(() => { 1389e41f4b71Sopenharmony_ci console.info("Green will show") 1390e41f4b71Sopenharmony_ci }) 1391e41f4b71Sopenharmony_ci .onWillHide(() => { 1392e41f4b71Sopenharmony_ci console.info("Green will hide") 1393e41f4b71Sopenharmony_ci }) 1394e41f4b71Sopenharmony_ci } 1395e41f4b71Sopenharmony_ci .vertical(false) 1396e41f4b71Sopenharmony_ci .scrollable(true) 1397e41f4b71Sopenharmony_ci .barMode(BarMode.Fixed) 1398e41f4b71Sopenharmony_ci .onChange((index:number)=>{ 1399e41f4b71Sopenharmony_ci console.info(index.toString()) 1400e41f4b71Sopenharmony_ci }) 1401e41f4b71Sopenharmony_ci .width('100%') 1402e41f4b71Sopenharmony_ci .backgroundColor(0xF1F3F5) 1403e41f4b71Sopenharmony_ci }.width('100%').height(200) 1404e41f4b71Sopenharmony_ci } 1405e41f4b71Sopenharmony_ci } 1406e41f4b71Sopenharmony_ci} 1407e41f4b71Sopenharmony_ci``` 1408e41f4b71Sopenharmony_ci 1409e41f4b71Sopenharmony_ci 1410