鴻蒙(HarmonyOS)項(xiàng)目方舟框架(ArkUI)之NavRouter組件
一、操作環(huán)境
操作系統(tǒng):? Windows 10 專業(yè)版、IDE:DevEco Studio 3.1、SDK:HarmonyOS 3.1+
二、NavRouter組件
導(dǎo)航組件,默認(rèn)提供點(diǎn)擊響應(yīng)處理,不需要開發(fā)者自定義點(diǎn)擊事件邏輯。
子組件
必須包含兩個(gè)子組件,其中第二個(gè)子組件必須為NavDestination。
接口
NavRouter()
事件
名稱 |
功能描述 |
---|---|
onStateChange(callback: (isActivated: boolean) => void) |
組件激活狀態(tài)切換時(shí)觸發(fā)該回調(diào)。返回值isActivated為true時(shí)表示激活,為false時(shí)表示未激活。 說明: 開發(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%')
}
}
圖例
你有時(shí)間常去我家看看我在這里謝謝你啦...
我家地址:亞丁號(hào)
最后送大家一首詩:
山高路遠(yuǎn)坑深,
大軍縱橫馳奔,文章來源:http://www.zghlxwxcb.cn/news/detail-831412.html
誰敢橫刀立馬?
惟有點(diǎn)贊加關(guān)注大軍。文章來源地址http://www.zghlxwxcb.cn/news/detail-831412.html
到了這里,關(guān)于鴻蒙(HarmonyOS)項(xiàng)目方舟框架(ArkUI)之NavRouter組件的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!