智能客服
你问我答,随时在线为你解决问题

























Tabs组件如何在TabBar添加页签之外的自定义组件,如文字和图片等?
使用浮层overlay可以实现,步骤如下:
- @Builder
- overlayExample() {
- Flex({ justifyContent: FlexAlign.SpaceBetween, direction: FlexDirection.Row, alignItems: ItemAlign.Center }) {
- Text('登录').fontSize(18).fontColor('#ffcd6c18');
- Image($r('app.media.search'))
- .width(24)
- .height(24);
- }
- .padding({ left: 20, right: 20 })
- .width('100%')
- .height(56)
- .hitTestBehavior(HitTestMode.Transparent); // 配置浮层不阻塞交互
- }
- Tabs() {
- TabContent() {
- Column().width('100%').height('100%').backgroundColor(Color.Pink);
- }.tabBar(SubTabBarStyle.of('订阅'));
-
- TabContent() {
- Column().width('100%').height('100%').backgroundColor(Color.Green);
- }.tabBar(SubTabBarStyle.of('推荐'));
-
- TabContent() {
- Column().width('100%').height('100%').backgroundColor(Color.Blue);
- }.tabBar(SubTabBarStyle.of('热门'));
- }
- .width('100%')
- .height('100%')
- .backgroundColor(0xf1f3f5)
- .barMode(this.barMode)
- .barWidth(200)
- .overlay(this.overlayExample(), { align: Alignment.Top });
完整示例参考如下:
- @Entry
- @Component
- struct TabsExample {
- text: string = '文本';
- barMode: BarMode = BarMode.Fixed;
-
- @Builder
- overlayExample() {
- Flex({ justifyContent: FlexAlign.SpaceBetween, direction: FlexDirection.Row, alignItems: ItemAlign.Center }) {
- Text('登录').fontSize(18).fontColor('#ffcd6c18');
- Image($r('app.media.search'))
- .width(24)
- .height(24);
- }
- .padding({ left: 20, right: 20 })
- .width('100%')
- .height(56)
- .hitTestBehavior(HitTestMode.Transparent); // 配置浮层不阻塞交互
- }
-
- build() {
- Column() {
- Tabs() {
- TabContent() {
- Column().width('100%').height('100%').backgroundColor(Color.Pink);
- }.tabBar(SubTabBarStyle.of('订阅'));
-
- TabContent() {
- Column().width('100%').height('100%').backgroundColor(Color.Green);
- }.tabBar(SubTabBarStyle.of('推荐'));
-
- TabContent() {
- Column().width('100%').height('100%').backgroundColor(Color.Blue);
- }.tabBar(SubTabBarStyle.of('热门'));
- }
- .width('100%')
- .height('100%')
- .backgroundColor(0xf1f3f5)
- .barMode(this.barMode)
- .barWidth(200)
- .overlay(this.overlayExample(), { align: Alignment.Top });
- }
- .width('100%')
- .height('100%');
- }
- }
智能客服
你问我答,随时在线为你解决问题
合作咨询
我们的专家服务团队将竭诚为您提供专业的合作咨询服务
解决方案
精准高效的一站式服务支持,助力开发者商业成功