国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

華為鴻蒙應(yīng)用--底部導(dǎo)航欄Tabs(自適應(yīng)手機(jī)和平板)-ArkTs

這篇具有很好參考價(jià)值的文章主要介紹了華為鴻蒙應(yīng)用--底部導(dǎo)航欄Tabs(自適應(yīng)手機(jī)和平板)-ArkTs。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

鴻蒙ArkTS Tabs組件開發(fā)底部導(dǎo)航欄,可自適應(yīng)平板和手機(jī),相當(dāng)于Android開發(fā)中的MainActivity+Fragment的底部導(dǎo)航欄模式。

華為鴻蒙應(yīng)用 csdn 底部導(dǎo)航欄,HarmonyOS,harmonyos,華為,鴻蒙系統(tǒng)華為鴻蒙應(yīng)用 csdn 底部導(dǎo)航欄,HarmonyOS,harmonyos,華為,鴻蒙系統(tǒng)

一、主頁:MainPage.ets
import { BreakpointSystem, BreakpointConstants, StyleConstants, PageConstants, } from '@ohos/common';  // 通用工具
import { Chat } from '@ohos/chat';  // 子模塊 相當(dāng)于Android 的Fragment
import { Contact } from '@ohos/Contact';  // 子模塊
import { Work } from '@ohos/Work';  //  子模塊
import { Mine } from '@ohos/Mine';  //  子模塊
import { buttonInfo, ButtonInfoModel } from '../viewmodel/MainPageData'; // 底部導(dǎo)航數(shù)據(jù)


@Entry
@Component
struct MainPage {
  @StorageProp('currentBreakpoint') currentBreakpoint: string = 'sm';
  @State currentPageIndex: number = 0;
  private breakpointSystem = new BreakpointSystem();
  aboutToAppear() {
    this.breakpointSystem.register();
  }
  aboutToDisappear() {
    this.breakpointSystem.unregister();
  }

  @Builder BottomNavigation(button: ButtonInfoModel) {
    Column({ space: PageConstants.BUTTON_SPACE }) {  //  static readonly BUTTON_SPACE: string = '6vp';
      Image(this.currentPageIndex === button.index ? button.selectImg : button.img)
        .objectFit(ImageFit.Contain)
        .width($r('app.float.main_image_size'))
        .height($r('app.float.main_image_size'))
      Text(button.title)
        .fontColor(this.currentPageIndex === button.index ? $r('app.color.focus_color') : $r('app.color.un_focus_color'))
        .opacity(this.currentPageIndex === button.index ? StyleConstants.FULL_OPACITY : StyleConstants.SIXTY_OPACITY)
        .fontWeight(StyleConstants.FONT_WEIGHT_FIVE)
        .textAlign(TextAlign.Center)
        .fontSize($r('app.float.micro_font_size'))
    }
    .width(StyleConstants.FULL_WIDTH)
    .height(StyleConstants.FULL_HEIGHT)
    .alignItems(HorizontalAlign.Center)
    .justifyContent(FlexAlign.Center)
  }

  build() {
    Column() {
      Tabs({
        barPosition: this.currentBreakpoint === BreakpointConstants.BREAKPOINT_LG ?
        BarPosition.Start : BarPosition.End,
        index: this.currentPageIndex,
      }) {
        TabContent() {
          Chat() // 子模塊
        }.tabBar(this.BottomNavigation(buttonInfo[0]))

        TabContent() {
          Contact() // 子模塊
        }.tabBar(this.BottomNavigation(buttonInfo[1]))

        TabContent() {
          Work() // 子模塊
        }.tabBar(this.BottomNavigation(buttonInfo[2]))

        TabContent() {
          Mine() // 子模塊
        }.tabBar(this.BottomNavigation(buttonInfo[3]))
      }
      .barWidth(this.currentBreakpoint === BreakpointConstants.BREAKPOINT_LG ?
      $r('app.float.bar_width') : StyleConstants.FULL_WIDTH)
      .barHeight(this.currentBreakpoint === BreakpointConstants.BREAKPOINT_LG ?
      StyleConstants.SIXTY_HEIGHT : $r('app.float.vp_fifty_six'))
      .vertical(this.currentBreakpoint === BreakpointConstants.BREAKPOINT_LG)
      .scrollable(false)
      .onChange((index: number) => {
        this.currentPageIndex = index;
        // 提前查詢數(shù)據(jù)
        // if (index === 1) {
        //   this.queryShopCart();
        // } else if (index === 2) {
        //   this.queryOrderList();
        // }
      })
    }
    .backgroundColor($r('app.color.page_background'))
  }
}

StyleConstants.ets:文章來源地址http://www.zghlxwxcb.cn/news/detail-810931.html

/**
 * Constants for common style.
 */
export class StyleConstants {
  /**
   * Component width percentage: 100%.
   */
  static readonly FULL_WIDTH: string = '100%';

  /**
   * Component height percentage: 100%.
   */
  static readonly FULL_HEIGHT: string = '100%';

  /**
   * Component height percentage: 70%.
   */
  static readonly SEVENTY_HEIGHT: string = '70%';

  /**
   * Component height percentage: 60%.
   */
  static readonly SIXTY_HEIGHT: string = '60%';

  /**
   * Component width percentage: 60%.
   */
  static readonly SIXTY_WIDTH: string = '60%';

  /**
   * Component height percentage: 50%.
   */
  static readonly FIFTY_HEIGHT: string = '50%';

  /**
   * Component height percentage: 50%.
   */
  static readonly HUNDRED_FIFTEEN_WIDTH: string = '115%';

  /**
   * Component space vp : 4.
   */
  static readonly FOUR_SPACE: string = '4vp';

  /**
   * Component space vp : 12.
   */
  static readonly TWELVE_SPACE: string = '12vp';

  /**
   * Component space vp : 14.
   */
  static readonly ITEM_SPACE: string = '14vp';

  /**
   * Component space vp : 15.
   */
  static readonly FIFTEEN_SPACE: string = '15vp';

  /**
   * Font weight value: 700.
   */
  static readonly FONT_WEIGHT_SEVEN: number = 700;

  /**
   * Font weight value: 500.
   */
  static readonly FONT_WEIGHT_FIVE: number = 500;

  /**
   * Font weight value: 400.
   */
  static readonly FONT_WEIGHT_FOUR: number = 400;

  /**
   * Text line value: 2.
   */
  static readonly TWO_TEXT_LINE: number = 2;

  /**
   * Component opacity value: 1.
   */
  static readonly FULL_OPACITY: number = 1;

  /**
   * Component opacity value: 0.6.
   */
  static readonly SIXTY_OPACITY: number = 0.6;

  /**
   * Component opacity value: 0.8.
   */
  static readonly EIGHTY_OPACITY: number = 0.8;

  /**
   * Component layout value: 1.
   */
  static readonly LAYOUT_WEIGHT: number = 1;

  /**
   * Flex basic value: 1.
   */
  static readonly FLEX_BASIC: number = 1;

  /**
   * Flex shrink value: 1.
   */
  static readonly FLEX_SHRINK: number = 1;

  /**
   * Flex grow value: 1.
   */
  static readonly FLEX_GROW: number = 1;

  /**
   * Swiper or list display count value: 1.
   */
  static readonly DISPLAY_ONE: number = 1;

  /**
   * Swiper or list display count value: 2.
   */
  static readonly DISPLAY_TWO: number = 2;

  /**
   * Swiper or list display count value: 3.
   */
  static readonly DISPLAY_THREE: number = 3;

  /**
   * Swiper or list display count value: 4.
   */
  static readonly DISPLAY_FOUR: number = 4;

  /**
   * Image aspect ratio value: 2.23.
   */
  static readonly IMAGE_ASPECT_RATIO: number = 2.25;

  /**
   * Number of value: 0.5.
   */
  static readonly HALF_ONE: number = 0.5;

  /**
   * Number of value: -1.
   */
  static readonly MINUS_ONE: number = -1;
}
二、BreakpointSystem.ets:響應(yīng)式設(shè)計(jì)的核心
import mediaQuery from '@ohos.mediaquery';
import { BreakpointConstants } from '../constants/BreakpointConstants';

declare interface BreakPointTypeOption<T> {
  sm?: T
  md?: T
  lg?: T
  xl?: T
  xxl?: T
}

/**
 * 媒體查詢(mediaquery)
 * 響應(yīng)式設(shè)計(jì)的核心
 */
export class BreakPointType<T> {
  options: BreakPointTypeOption<T>

  constructor(option: BreakPointTypeOption<T>) {
    this.options = option
  }

  getValue(currentBreakPoint: string): T {
    return this.options[currentBreakPoint] as T
  }
}

export class BreakpointSystem {
  private currentBreakpoint: string = '';
  private smListener?: mediaQuery.MediaQueryListener;
  private mdListener?: mediaQuery.MediaQueryListener;
  private lgListener?: mediaQuery.MediaQueryListener;

  private updateCurrentBreakpoint(breakpoint: string) {
    if (this.currentBreakpoint !== breakpoint) {
      this.currentBreakpoint = breakpoint;
      AppStorage.Set<string>(BreakpointConstants.CURRENT_BREAKPOINT, this.currentBreakpoint);
    }
  }

  private isBreakpointSM = (mediaQueryResult: mediaQuery.MediaQueryResult) => {
    if (mediaQueryResult.matches) {
      this.updateCurrentBreakpoint(BreakpointConstants.BREAKPOINT_SM);
    }
  }
  private isBreakpointMD = (mediaQueryResult: mediaQuery.MediaQueryResult) => {
    if (mediaQueryResult.matches) {
      this.updateCurrentBreakpoint(BreakpointConstants.BREAKPOINT_MD);
    }
  }
  private isBreakpointLG = (mediaQueryResult: mediaQuery.MediaQueryResult) => {
    if (mediaQueryResult.matches) {
      this.updateCurrentBreakpoint(BreakpointConstants.BREAKPOINT_LG);
    }
  }

  public register() {
    this.smListener = mediaQuery.matchMediaSync(BreakpointConstants.RANGE_SM);
    this.smListener.on('change', this.isBreakpointSM);
    this.mdListener = mediaQuery.matchMediaSync(BreakpointConstants.RANGE_MD);
    this.mdListener.on('change', this.isBreakpointMD);
    this.lgListener = mediaQuery.matchMediaSync(BreakpointConstants.RANGE_LG);
    this.lgListener.on('change', this.isBreakpointLG);
  }

  public unregister() {
    this.smListener?.off('change', this.isBreakpointSM);
    this.mdListener?.off('change', this.isBreakpointMD);
    this.lgListener?.off('change', this.isBreakpointLG);
  }
}
BreakpointConstants.ets: 
export class BreakpointConstants {
  /**
   * Breakpoints that represent small device types.
   */
  static readonly BREAKPOINT_SM: string = 'sm';

  /**
   * Breakpoints that represent middle device types.
   */
  static readonly BREAKPOINT_MD: string = 'md';

  /**
   * Breakpoints that represent large device types.
   */
  static readonly BREAKPOINT_LG: string = 'lg';

  /**
   * Current breakpoints that to query the device types.
   */
  static readonly CURRENT_BREAKPOINT: string = 'currentBreakpoint';

  /**
   * Range of the small device width.
   */
  static readonly RANGE_SM: string = '(320vp<=width<520vp)';

  /**
   * Range of the middle device width.
   */
  static readonly RANGE_MD: string = '(520vp<=width<840vp)';

  /**
   * Range of the large device width.
   */
  static readonly RANGE_LG: string = '(840vp<=width)';
}
三、ButtonInfoModel.ets:底部導(dǎo)航按鈕數(shù)據(jù)?
export class ButtonInfoModel {
  index: number ;  // 序號(hào)
  img: Resource;  // 未選中圖片
  selectImg: Resource ; // 選中圖片
  title: Resource; // 按鈕名稱
}

const buttonInfo: ButtonInfoModel[] = [
  {
    index: 0,
    img: $r('app.media.ic_chat_off'),
    selectImg: $r('app.media.ic_chat_on'),
    title: $r('app.string.chat')
  },
  {
    index: 1,
    img: $r('app.media.ic_contact_off'),
    selectImg: $r('app.media.ic_contact_on'),
    title: $r('app.string.contact')
  },
  {
    index: 2,
    img: $r('app.media.ic_work_off'),
    selectImg: $r('app.media.ic_work_on'),
    title: $r('app.string.work')
  },
  {
    index: 3,
    img: $r('app.media.ic_mine_off'),
    selectImg: $r('app.media.ic_mine_on'),
    title: $r('app.string.mine')
  }
]

export { buttonInfo }

到了這里,關(guān)于華為鴻蒙應(yīng)用--底部導(dǎo)航欄Tabs(自適應(yīng)手機(jī)和平板)-ArkTs的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 鴻蒙原生應(yīng)用開發(fā)-折疊屏、平板設(shè)備服務(wù)卡片適配

    鴻蒙原生應(yīng)用開發(fā)-折疊屏、平板設(shè)備服務(wù)卡片適配

    為不同尺寸的卡片提供不同的功能 在卡片開發(fā)過程中請(qǐng)考慮適配不同尺寸的設(shè)備,特別是在折疊屏和平板設(shè)備上,設(shè)備屏幕尺寸的變化直接影響了卡片內(nèi)容的展示。請(qǐng)發(fā)揮想象力設(shè)計(jì)具有自適應(yīng)能力的卡片,避免在卡片內(nèi)容不做任何處理的情況下直接適配成較大尺寸,原則上

    2024年02月03日
    瀏覽(24)
  • 華為手機(jī)(鴻蒙OS)開啟adb調(diào)試權(quán)限

    華為手機(jī)(鴻蒙OS)開啟adb調(diào)試權(quán)限

    背景:做自動(dòng)化測試的應(yīng)該就不用我解釋adb是什么了吧,現(xiàn)在需要開啟華為手機(jī)的adb調(diào)試權(quán)限,別上來就搜開發(fā)者選項(xiàng),肯定是搜不到的,按照如下配置逐步來就行了,找不到就直接進(jìn)入設(shè)置最上面有個(gè)搜索框 1、進(jìn)入設(shè)置-關(guān)于手機(jī)-版本號(hào)(連續(xù)點(diǎn)擊7次) 2、這里面有兩次認(rèn)

    2024年02月11日
    瀏覽(20)
  • appium+華為鴻蒙手機(jī)自動(dòng)化(環(huán)境配置)

    appium+華為鴻蒙手機(jī)自動(dòng)化(環(huán)境配置)

    安裝python appium client,cmd中輸入 pip install appium-python-client 等待安裝完成即可。 JDK官方網(wǎng)址:Download 建議選擇exe,可以選擇路徑,而且安裝完成之后,java的環(huán)境變量都會(huì)保存在javapath的目錄中。 如果你的JDK版本不是新的,那么你在安裝完成之后,可能需要配置一下環(huán)境變量。

    2023年04月26日
    瀏覽(36)
  • 【鴻蒙應(yīng)用ArkTS開發(fā)系列】- 導(dǎo)航欄Tab組件使用講解

    【鴻蒙應(yīng)用ArkTS開發(fā)系列】- 導(dǎo)航欄Tab組件使用講解

    現(xiàn)在市場上的大部分應(yīng)用,主頁都是才用底部導(dǎo)航欄菜單作為頁面主體框架來展示, 在鴻蒙中是使用Tabs組件實(shí)現(xiàn),下面我們開始講解Tab組件的使用。 Tabs是一個(gè)通過頁簽進(jìn)行內(nèi)容視圖切換的容器組件,每個(gè)頁簽對(duì)應(yīng)一個(gè)內(nèi)容視圖,它僅可包含子組件TabContent,同時(shí)搭配 TabsCo

    2024年01月16日
    瀏覽(37)
  • 二手榮耀華為手機(jī)/平板以前用的賬號(hào)密碼都忘了如何清除解開.激活重置恢復(fù)找回解開方法教程

    二手榮耀華為手機(jī)/平板以前用的賬號(hào)密碼都忘了如何清除解開.激活重置恢復(fù)找回解開方法教程

    二手榮耀華為手機(jī)/平板以前用的賬號(hào)密碼都忘了,現(xiàn)在打開設(shè)備鎖定華為手機(jī)號(hào)碼變更如何解鎖激活碼榮耀華為手機(jī)/平板激活需要輸入賬號(hào)密碼?不記得了怎么進(jìn)去號(hào)也停了我給強(qiáng)制恢復(fù)出廠設(shè)置了,結(jié)果手機(jī)被鎖定了,現(xiàn)在激活設(shè)備激活不了,需要賬號(hào)的密的我的華為榮耀

    2024年02月10日
    瀏覽(23)
  • 華為新發(fā)布的鴻蒙與目前華為手機(jī)的鴻蒙系統(tǒng)有什么差異,OpenHarmony、HarmonyOS、HarmonyOS NEXT的區(qū)別詳解

    最近工作中需要進(jìn)行鴻蒙適配,一開始我有個(gè)疑問,今年新發(fā)布的鴻蒙系統(tǒng),與目前華為手機(jī)使用的鴻蒙系統(tǒng)有什么差異?為什么要專門進(jìn)行適配?如果大家也有類似的疑問,看完這篇就明白了。 今年華為在鴻蒙生態(tài)千帆啟航儀式上正式發(fā)布了鴻蒙原生操作系統(tǒng)——HarmonyO

    2024年04月17日
    瀏覽(25)
  • 華為手機(jī)Mate9不能升級(jí)鴻蒙系統(tǒng)的解決方法

    升級(jí)方式 進(jìn)入手機(jī)設(shè)置-系統(tǒng)和更新-軟件更新(或者進(jìn)入系統(tǒng)應(yīng)用【服務(wù)】內(nèi)更新),進(jìn)入后會(huì)自動(dòng)檢測;檢測到版本,直接下載安裝,下載安裝后,查看版本是否是鴻蒙,如果不是,繼續(xù)檢測,直到提示已經(jīng)是最新版本或未檢測到有新的安裝包之類的提示。 遇到的問題 我

    2024年02月12日
    瀏覽(33)
  • 鴻蒙手機(jī)華為meta 30 第一次鏈接電腦下載驅(qū)動(dòng)

    鴻蒙手機(jī)華為meta 30 第一次鏈接電腦下載驅(qū)動(dòng)

    第一步下載 華為手機(jī)助手HiSuite官方下載 | 華為官網(wǎng) usb連接電腦后要手機(jī)要開啟 USB調(diào)試模式,具體開啟方式點(diǎn)擊手機(jī)設(shè)置-》關(guān)于手機(jī)-》快速點(diǎn)擊五次HarmonyOs版本 然后就進(jìn)入了開發(fā)者模式 ,點(diǎn)擊返回-》系統(tǒng)和更新-》開發(fā)人員選項(xiàng)-》開啟并開啟usb調(diào)試 ?第二部設(shè)置 ? ?

    2024年02月16日
    瀏覽(18)
  • adb wifi連接調(diào)試應(yīng)用--適用于手機(jī)、平板、電視TV等

    adb wifi連接調(diào)試應(yīng)用--適用于手機(jī)、平板、電視TV等

    今天需要adb WiFi連接電視調(diào)試東西,發(fā)現(xiàn)使用了網(wǎng)上的方法后還是無法連接adb WiFi成功,后來摸索了下,便成功了,根本原因還是需要確保電腦、手機(jī)或者電視他們?cè)谕粋€(gè)WiFi內(nèi)。我的 做法就是電腦開個(gè)熱點(diǎn),手機(jī)或者電視連接這個(gè)熱點(diǎn)就肯定沒有問題了? 首先電腦開個(gè)熱點(diǎn)

    2024年02月10日
    瀏覽(26)
  • 華為鴻蒙開發(fā)者工具DevEco Studio設(shè)備欄不識(shí)別鴻蒙手機(jī)模擬器解決方法

    華為鴻蒙開發(fā)者工具DevEco Studio設(shè)備欄不識(shí)別鴻蒙手機(jī)模擬器解決方法

    在學(xué)習(xí)鴻蒙開發(fā)的路上,有很多小伙伴遇到過安裝了手機(jī)模擬器,但是開發(fā)工具設(shè)備欄不識(shí)別手機(jī)設(shè)備的問題,如下圖,明明模擬器都安裝了,但為什么設(shè)備欄不顯示呢? 已windows系統(tǒng)為例,解決方法如下 當(dāng)開啟DevEco Studio工具和鴻蒙手機(jī)模擬器后,手機(jī)設(shè)備不識(shí)別。需要先關(guān)

    2024年02月02日
    瀏覽(141)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包