鴻蒙移動(dòng)端常用UI——tab切換欄

效果圖


image.png

tab切換欄全部代碼

import { BSText } from '../../../components/BSUI'
import { AppBarWidget } from './AppBarWidget'


@Entry
@Component
struct TabPage {
  @State currentIndex: number = 0

  @Builder TabBuilder(index: number, title: string,) {
    Column() {
      Divider().height(5).color(Color.Transparent).width(20)
      BSText({title:title.toString(),fontColor:this.currentIndex === index ?  '#F33F3F':'#333333',fontSize:15})
      Divider().color(this.currentIndex === index ?  Color.Red:Color.Transparent).width(30)
    }.justifyContent(FlexAlign.SpaceBetween).layoutWeight(1).width(80)
  }

  build() {
    Column(){
      AppBarWidget({title:'TabPage'})
      Column() {
        //布局區(qū)別:BarPosition.Start、vertical(false)
        Tabs({ barPosition: BarPosition.Start }) {
          TabContent() {
            Column().width('100%').height('100%').backgroundColor(Color.Pink)
          }.tabBar(this.TabBuilder(0,'全部'))

          TabContent() {
            Column().width('100%').height('100%').backgroundColor(Color.Yellow)
          }.tabBar(this.TabBuilder(1,'待發(fā)貨'))

          TabContent() {
            Column().width('100%').height('100%').backgroundColor(Color.Blue)
          }.tabBar(this.TabBuilder(2,'已發(fā)貨'))

          TabContent() {
            Column().width('100%').height('100%').backgroundColor(Color.Green)
          }.tabBar(this.TabBuilder(3,'已收貨'))

          TabContent() {
            Column().width('100%').height('100%').backgroundColor(Color.Green)
          }.tabBar(this.TabBuilder(3,'確認(rèn)'))

        }
        .vertical(false)
        .scrollable(true)
        .barMode(BarMode.Scrollable)
        .onChange((index: number) => {
          this.currentIndex = index;
          console.info(index.toString())
        })
        .width('100%')
        .backgroundColor(0xF1F3F5)
      }.width('100%').layoutWeight(1)
    }
  }
}

ps:
1、BS開頭的API是為了方便開發(fā)和維護(hù),對(duì)鴻蒙UI做了一層簡(jiǎn)單的封裝,并且會(huì)陸續(xù)進(jìn)行更新.
2、基于API Version9版本.
3、看到文章覺得還OK麻煩留個(gè)贊??謝謝啦~

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 最終效果圖 底部tab欄、底部導(dǎo)航和badge全部代碼: ps:1、BS開頭的API是為了方便開發(fā)和維護(hù),對(duì)鴻蒙U...
    Yelena_CYL閱讀 915評(píng)論 0 2
  • 用兩張圖告訴你,為什么你的 App 會(huì)卡頓? - Android - 掘金 Cover 有什么料? 從這篇文章中你...
    hw1212閱讀 13,994評(píng)論 2 59
  • 第一步:安裝Node 1、打開NodeJS的官網(wǎng),下載和自己系統(tǒng)相配的NodeJS的安裝程序,包括32位還是64位...
    子瞻是也閱讀 920評(píng)論 0 3
  • 1. 手機(jī)測(cè)試概念 傳統(tǒng)手機(jī)測(cè)試 VS 手機(jī)應(yīng)用軟件測(cè)試 傳統(tǒng)手機(jī)測(cè)試 傳統(tǒng)的手機(jī)測(cè)試,我們說的是指測(cè)試手機(jī)本...
    連貓都嫌棄我閱讀 622評(píng)論 0 0
  • 一、 手機(jī)測(cè)試概念 傳統(tǒng)手機(jī)測(cè)試 VS 手機(jī)應(yīng)用軟件測(cè)試 傳統(tǒng)手機(jī)測(cè)試:指測(cè)試手機(jī)本身比如抗壓,抗摔,抗疲勞,抗低...
    Anwfly閱讀 1,229評(píng)論 0 5

友情鏈接更多精彩內(nèi)容