鸿蒙开发中页面透明如何设置?

鸿蒙开发中页面透明如何设置?现有两个page,页面B只有中间一部分UI,设置背景颜色是透明的。期望页面A跳转到页面B时,页面B的UI展示出来,透明的地方展示页面A的内容,但是目前完全看不到页面A。

本文参与了 【 HarmonyOS NEXT 技术问答冲榜,等你来战!】欢迎正在阅读的你也加入。

阅读 607
1 个回答

具体解决方案:
router路由模式请参考下面demo:

// Page1.ets 
@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 
 
@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 
 
  windowStage.loadContent('pages/Page231206095213071', (err, data) => { 
  if (err.code) { 
 
  return; 
} 
AppStorage.setAndLink("windowStage", windowStage);// 关键代码 

}); 
}

支持 NavDestination支持Dialog类型页面:https://developer.huawei.com/consumer/cn/doc/harmonyos-refere...枚举说明-11
NavDestinationMode.STANDARD: 标准类型
NavDestination的生命周期NavDestinationMode.DIALOG: 默认透明。

本文参与了 【 HarmonyOS NEXT 技术问答冲榜,等你来战!】欢迎正在阅读的你也加入。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进