请问一下tab按钮组切换效果

tab按钮组切换效果

HarmonyOS
2024-05-26 14:59:41
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
coolhead2000

核心代码

import { 
  ItemRestriction, 
  SegmentButton, 
  SegmentButtonItemTuple, 
  SegmentButtonOptions, 
  SegmentButtonTextItem 
} from '@ohos.arkui.advanced.SegmentButton' 
 
@Entry 
@Component 
struct Index { 
  // 配置按钮组数组 
  @State tabOptions: SegmentButtonOptions = SegmentButtonOptions.tab({ 
    buttons: [ 
      { text: '美妆' }, 
      { text: '衣服' }, 
      { text: '鞋子' } 
    ] as ItemRestriction<SegmentButtonTextItem>, 
    backgroundBlurStyle: BlurStyle.BACKGROUND_THICK 
  }) 
  @State singleSelectCapsuleOptions: SegmentButtonOptions = SegmentButtonOptions.capsule({ 
    buttons: [ 
      { text: '美妆' }, 
      { text: '衣服' }, 
      { text: '鞋子' } 
    ] as SegmentButtonItemTuple, 
    backgroundBlurStyle: BlurStyle.BACKGROUND_THICK 
  }) 
  // 配置按钮组默认选中项 
  @State tabSelectedIndexes: number[] = [2] 
  @State singleSelectCapsuleSelectedIndexes: number[] = [1] 
 
  build() { 
    Row() { 
      Column() { 
        Column({ space: 25 }) { 
          SegmentButton({ 
            options: this.tabOptions, 
            selectedIndexes: $tabSelectedIndexes 
          }) 
          SegmentButton({ 
            options: this.singleSelectCapsuleOptions, 
            selectedIndexes: $singleSelectCapsuleSelectedIndexes 
          }) 
        } 
        .width('90%') 
      } 
      .width('100%') 
    } 
    .height('100%') 
  } 
}
  • 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.

实现效果

注明适配的版本信息

  • IDE:DevEco Studio 4.0.3.600
  • SDK:HarmoneyOS 4.0.10.11
分享
微博
QQ
微信
回复
2024-05-27 19:57:48
相关问题
HarmonyOS 咨询一下Tab中的些写法
914浏览 • 1回复 待解决
请问一下鸿蒙的pad应用该如何签名?
9241浏览 • 1回复 待解决
ob有如何报错,麻烦帮忙看一下
5880浏览 • 1回复 待解决
HarmonyOS tab切换demo
642浏览 • 1回复 待解决
请教一下如何实现函数的重载
1845浏览 • 1回复 待解决
请教一下关于应用分栏实现
2060浏览 • 1回复 待解决
请教一下如何开关闪光灯
1558浏览 • 1回复 待解决
请教一下关于Ticktimer 的疑问?
4395浏览 • 1回复 待解决
编译OpenHarmony2.0失败,求助一下
9835浏览 • 3回复 已解决
提问
该提问已有0人参与 ,帮助了0人