router路由模式请参考下面demo:// Page1.ets import window from '@ohos.window'; @Entry @Component struct Page2 { @State message: string = 'page Page2'; onPageHide() { console.log("pageHide") } build() { Row() { Column() { Text(this.message) .fontSize(50) .fontWeight(FontWeight.Bold) Button("pageB").onClick(() => { let windowStege: window.WindowStage = AppStorage.get("windowStage") as window.WindowStage; windowStege.createSubWindow("hello", (err, win) => { win.setUIContent('pages/Page2'); win.showWindow(); }) }) } .width('100%') } .height('100%') .backgroundColor(Color.Pink) } } // Page2.ets import window from '@ohos.window'; @Entry @Component struct Index { @State message: string = 'page Index'; aboutToAppear() { window.findWindow("hello").setWindowBackgroundColor("#00000000") } onBackPress() { window.findWindow("hello").destroyWindow().then((res) => { console.log("destroyWindow success") }).catch(() => { console.log("destroyWindow fail") }) return true } build() { Row() { Column() { Text(this.message) .fontSize(50) .fontWeight(FontWeight.Bold) } .width('100%') .backgroundColor(Color.Red) } .alignItems(VerticalAlign.Top) .height('100%') .backgroundColor("#80ffffff") } } //注意需要在EntryAbility里面添加关键代码那一行 onWindowStageCreate(windowStage: window.WindowStage): void { // Main window is created, set main page for this ability hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); windowStage.loadContent('pages/Page231206095213071', (err, data) => { if (err.code) { hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); return; } AppStorage.setAndLink("windowStage", windowStage);// 关键代码 hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); }); }AppStorage.setAndLink(“windowStage”, windowStage);// 关键代码 只需要看这行的关键代码就可以了,这个是配置windowStage.loadContent(‘pages/page1’) ,这个demo是page1跳转page2,page2是透明的效果
router路由模式请参考下面demo:
AppStorage.setAndLink(“windowStage”, windowStage);// 关键代码 只需要看这行的关键代码就可以了,这个是配置windowStage.loadContent(‘pages/page1’) ,这个demo是page1跳转page2,page2是透明的效果