HarmonyOS 底部自定义tabbar凹凸弧度效果

HarmonyOS
2024-12-24 17:55:23
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zxjiu

参考如下demo:

import { CustomTabBar } from './CustomTabBar';
@Entry
@Component
struct Index {
  tabController: TabsController = new TabsController()
  @State currentIndex: number = 0;
  @Provide('pageInfos') pageInfos: NavPathStack = new NavPathStack()
  @Builder

  build() {
    Navigation(this.pageInfos) {
      Stack() {
        Flex({ direction: FlexDirection.Column }) {
          Tabs({
            barPosition: BarPosition.End, //底部导航
            index: this.currentIndex,
            controller: this.tabController
          }) {
            TabContent() {
              Text('首页')
            }

            TabContent() {
              Text('消息')
            }

            TabContent() {
              Text('服务')
            }

            TabContent() {
              Text('小慧')
            }

            TabContent() {
              Text('我的')
            }
          }
          .animationDuration(0) //去掉切换页面的动画
          .scrollable(false) //去掉左右滑动的效果
          .barHeight(0)
          .layoutWeight(1)
          .scrollable(false)
          .onChange((index: number) => {
            this.currentIndex = index
          })

          CustomTabBar({
            currentIndex: $currentIndex
          })
        }
      }.width('100%')
      .height('100%')
    }
    .hideTitleBar(true)
    .mode(NavigationMode.Stack)
  }
}

// CustomTabBar.ets


@Preview
@Component
export struct CustomTabBar {
  @Link currentIndex: number;
  @State subscriptStr: string = ''

  @Builder
  subscript() {
    Row() {
      Text(this.subscriptStr)
        .textAlign(TextAlign.Center)
        .width('100%')
        .fontColor(Color.White)
        .fontSize(12)
    }
    .position({ x: 10, y: -10 })
    .width(25)
    .height(20)
    .backgroundColor(Color.Red)
    .borderRadius(10)
  }

  build() {
    Flex({
      direction: FlexDirection.Row,
      alignItems: ItemAlign.Center,
      justifyContent: FlexAlign.SpaceAround
    }) {
      ForEach(TabsInfos, (item: tabInfo, index: number) => {
        Column() {
          if (index === 2) {
            Column({ space: 10 }){
              Column(){
                Image(item.icon)
                  .size({width: 60 , height: 45 })
                  .interpolation(ImageInterpolation.High)
              }
              .padding(2)
              .margin({top:-30})
              .backgroundColor(Color.Transparent)

              Text(item.title)
                .fontSize(16)
                .fontColor(this.currentIndex === index ? '#333333':Color.Blue)
            }
          } else {
            Column({ space: 5 }){
              Image(this.currentIndex === index ? item.iconSel : item.icon)
                .size({ width: 30, height: 30 })
              Text(item.title)
                .fontSize(16)
                .fontColor(this.currentIndex === index ? '#333333':Color.Blue)
            }
          }
        }
        .onClick(() => {
          this.currentIndex = index
        })
      }, (item: tabInfo) => JSON.stringify(item))
    }
    .padding({ top: 5, bottom: Number(AppStorage.get('bottomRectHeight')) })
    .backgroundColor(Color.White)
    .shadow({radius:10,color:"#fff8f5f5", offsetY: -13})
  }
}

//  constantData.ets
export interface tabInfo {
  icon: Resource
  iconSel: Resource
  title: string
}

export const TabsInfos: tabInfo[] = [
  {
    icon: $r('app.media.icon'),
    iconSel: $r('app.media.weathergrey'),
    title: '首页'
  },
  {
    icon: $r('app.media.startIcon'),
    iconSel: $r('app.media.startIcon'),
    title: '消息'
  },
  {
    icon: $r('app.media.service'),
    iconSel: $r('app.media.service'),
    title: '服务'
  },
  {
    icon: $r('app.media.icon'),
    iconSel: $r('app.media.icon'),
    title: '小慧'
  },
  {
    icon: $r('app.media.icon'),
    iconSel: $r('app.media.icon'),
    title: '我的'
  },
]
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
  • 109.
  • 110.
  • 111.
  • 112.
  • 113.
  • 114.
  • 115.
  • 116.
  • 117.
  • 118.
  • 119.
  • 120.
  • 121.
  • 122.
  • 123.
  • 124.
  • 125.
  • 126.
  • 127.
  • 128.
  • 129.
  • 130.
  • 131.
  • 132.
  • 133.
  • 134.
  • 135.
  • 136.
  • 137.
  • 138.
  • 139.
  • 140.
  • 141.
  • 142.
  • 143.
  • 144.
  • 145.
  • 146.
  • 147.
  • 148.
  • 149.
  • 150.
  • 151.
  • 152.
  • 153.
  • 154.
  • 155.
  • 156.
  • 157.
  • 158.
  • 159.
  • 160.
  • 161.
  • 162.
分享
微博
QQ
微信
回复
2024-12-24 20:12:01
相关问题
HarmonyOS 自定义tabbar左对齐
607浏览 • 1回复 待解决
HarmonyOS 自定义tabbar组件开发
821浏览 • 1回复 待解决
HarmonyOS 怎么自定义Tab的Tabbar
716浏览 • 1回复 待解决
HarmonyOS CoverFlow效果自定义组件实现
1126浏览 • 1回复 待解决
TextInput是否能自定义hover效果
2969浏览 • 1回复 待解决
自定义弹窗自定义转场动画
1945浏览 • 1回复 待解决
HarmonyOS tabbar悬停效果
1085浏览 • 1回复 待解决
HarmonyOS 定义自定义组件
1036浏览 • 1回复 待解决