赞
踩
鸿蒙(HarmonyOS)项目方舟框架(ArkUI)之TabContent容器组件
操作系统: Windows 10 专业版、IDE:DevEco Studio 3.1、SDK:HarmonyOS 3.1+
仅在Tabs中使用,对应一个切换页签的内容视图。
支持单个子组件。
TabContent()
除支持通用属性外,还支持以下属性:
名称 | 参数类型 | 描述 |
---|---|---|
tabBar | string | Resource | { icon?: string | Resource, text?: string |Resource } | CustomBuilder8+ | 设置TabBar上显示内容。 CustomBuilder: 构造器,内部可以传入组件(API8版本以上适用)。 说明: 如果icon采用svg格式图源,则要求svg图源删除其自有宽高属性值。如采用带有自有宽高属性的svg图源,icon大小则是svg本身内置的宽高属性值大小。 |
tabBar9+ | 设置TabBar上显示内容。 SubTabBarStyle: 子页签样式,参数为文字。 BottomTabBarStyle: 底部页签和侧边页签样式,参数为文字和图片。 说明: 底部样式没有下划线效果。icon异常时显示灰色图块。 |
说明
子页签样式。
constructor(content: string | Resource)
SubTabBarStyle的构造函数。
参数:
参数名 | 参数类型 | 必填 | 参数描述 |
---|---|---|---|
content | string | Resource | 是 | 页签内的文字内容。 |
底部页签和侧边页签样式。
constructor(icon: string | Resource, text: string | Resource)
BottomTabBarStyle的构造函数。
参数:
- // xxx.ets
- @Entry
- @Component
- struct TabBarStyleExample {
- build() {
- Column({ space: 5 }) {
- Text("子页签样式")
- Column() {
- Tabs({ barPosition: BarPosition.Start }) {
- TabContent() {
- Column().width('100%').height('100%').backgroundColor(Color.Pink)
- }.tabBar(new SubTabBarStyle('Pink'))
-
- TabContent() {
- Column().width('100%').height('100%').backgroundColor(Color.Yellow)
- }.tabBar(new SubTabBarStyle('Yellow'))
-
- TabContent() {
- Column().width('100%').height('100%').backgroundColor(Color.Blue)
- }.tabBar(new SubTabBarStyle('Blue'))
-
- TabContent() {
- Column().width('100%').height('100%').backgroundColor(Color.Green)
- }.tabBar(new SubTabBarStyle('Green'))
- }
- .vertical(false)
- .scrollable(true)
- .barMode(BarMode.Fixed)
- .onChange((index: number) => {
- console.info(index.toString())
- })
- .width('100%')
- .backgroundColor(0xF1F3F5)
- }.width('100%').height(200)
- Text("底部页签样式")
- Column() {
- Tabs({ barPosition: BarPosition.End }) {
- TabContent() {
- Column().width('100%').height('100%').backgroundColor(Color.Pink)
- }.tabBar(new BottomTabBarStyle($r('sys.media.ohos_app_icon'), 'pink'))
-
- TabContent() {
- Column().width('100%').height('100%').backgroundColor(Color.Yellow)
- }.tabBar(new BottomTabBarStyle($r('sys.media.ohos_app_icon'), 'Yellow'))
-
- TabContent() {
- Column().width('100%').height('100%').backgroundColor(Color.Blue)
- }.tabBar(new BottomTabBarStyle($r('sys.media.ohos_app_icon'), 'Blue'))
-
- TabContent() {
- Column().width('100%').height('100%').backgroundColor(Color.Green)
- }.tabBar(new BottomTabBarStyle($r('sys.media.ohos_app_icon'), 'Green'))
- }
- .vertical(false)
- .scrollable(true)
- .barMode(BarMode.Fixed)
- .onChange((index: number) => {
- console.info(index.toString())
- })
- .width('100%')
- .backgroundColor(0xF1F3F5)
- }.width('100%').height(200)
- Text("侧边页签样式")
- Column() {
- Tabs({ barPosition: BarPosition.Start }) {
- TabContent() {
- Column().width('100%').height('100%').backgroundColor(Color.Pink)
- }.tabBar(new BottomTabBarStyle($r('sys.media.ohos_app_icon'), 'pink'))
-
- TabContent() {
- Column().width('100%').height('100%').backgroundColor(Color.Yellow)
- }.tabBar(new BottomTabBarStyle($r('sys.media.ohos_app_icon'), 'Yellow'))
-
- TabContent() {
- Column().width('100%').height('100%').backgroundColor(Color.Blue)
- }.tabBar(new BottomTabBarStyle($r('sys.media.ohos_app_icon'), 'Blue'))
-
- TabContent() {
- Column().width('100%').height('100%').backgroundColor(Color.Green)
- }.tabBar(new BottomTabBarStyle($r('sys.media.ohos_app_icon'), 'Green'))
- }
- .vertical(true).scrollable(true).barMode(BarMode.Fixed)
- .onChange((index: number) => {
- console.info(index.toString())
- })
- .width('100%')
- .backgroundColor(0xF1F3F5)
- }.width('100%').height(400)
- }
- }
- }

你有时间常去我家看看我在这里谢谢你啦...
我家地址:亚丁号
最后送大家一首诗:
山高路远坑深,
大军纵横驰奔,
谁敢横刀立马?
惟有点赞加关注大军。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。