W3Cschool
恭喜您成為首批注冊(cè)用戶(hù)
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
導(dǎo)航組件,默認(rèn)提供點(diǎn)擊響應(yīng)處理,不需要開(kāi)發(fā)者自定義點(diǎn)擊事件邏輯。
該組件從API Version 9開(kāi)始支持。后續(xù)版本如有新增內(nèi)容,則采用上角標(biāo)單獨(dú)標(biāo)記該內(nèi)容的起始版本。
必須包含兩個(gè)子組件,其中第二個(gè)子組件必須為NavDestination。
子組件個(gè)數(shù)異常時(shí):
名稱(chēng) | 功能描述 |
---|---|
onStateChange(callback: (isActivated: boolean) => void) | 組件激活狀態(tài)切換時(shí)觸發(fā)該回調(diào)。返回值isActivated為true時(shí)表示激活,為false時(shí)表示未激活。 說(shuō)明: 開(kāi)發(fā)者點(diǎn)擊激活NavRouter,加載對(duì)應(yīng)的NavDestination子組件時(shí),回調(diào)onStateChange(true)。NavRouter對(duì)應(yīng)的NavDestination子組件不再顯示時(shí),回調(diào)onStateChange(false)。 |
- // xxx.ets
- @Entry
- @Component
- struct NavRouterExample {
- @State isActiveWLAN: boolean = false
- @State isActiveBluetooth: boolean = false
- build() {
- Column() {
- Navigation() {
- NavRouter() {
- Row() {
- Row().width(30).height(30).borderRadius(30).margin({ left: 3, right: 10 }).backgroundColor(Color.Pink)
- Text(`WLAN`)
- .fontSize(22)
- .fontWeight(500)
- .textAlign(TextAlign.Center)
- }
- .width('90%')
- .height(72)
- NavDestination() {
- Flex({ direction: FlexDirection.Row }) {
- Text('未找到可用WLAN').fontSize(30).padding({ left: 15 })
- }
- }.hideTitleBar(false).backgroundColor('#0c182431')
- }.backgroundColor(this.isActiveWLAN ? '#ccc' : '#fff')
- .borderRadius(24)
- .onStateChange((isActivated: boolean) => {
- this.isActiveWLAN = isActivated
- })
- NavRouter() {
- Row() {
- Row().width(30).height(30).borderRadius(30).margin({ left: 3, right: 10 }).backgroundColor(Color.Pink)
- Text(`藍(lán)牙`)
- .fontSize(22)
- .fontWeight(500)
- .textAlign(TextAlign.Center)
- }
- .width('90%')
- .height(72)
- NavDestination() {
- Flex({ direction: FlexDirection.Row }) {
- Text('未找到可用藍(lán)牙').fontSize(30).padding({ left: 15 })
- }
- }.hideTitleBar(false).backgroundColor('#0c182431')
- }.backgroundColor(this.isActiveBluetooth ? '#ccc' : '#fff')
- .borderRadius(24)
- .onStateChange((isActivated: boolean) => {
- this.isActiveBluetooth = isActivated
- })
- }
- .title('設(shè)置')
- .titleMode(NavigationTitleMode.Free)
- .mode(NavigationMode.Auto)
- .hideTitleBar(false)
- .hideToolBar(true)
- }.height('100%')
- }
- }
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: