HarmonyOS 用navigation导航,如何实现透明背景页面效果呢?

请问如何使得一个页面背景是透明的呢,就是能看到下面的页面

阅读 593
1 个回答

此示例即可navigation透明

import { webview } from '@kit.ArkWeb';
@Entry
@Component
struct Index {
  @Provide('NavPathStack') pageStack: NavPathStack = new NavPathStack()

  @Builder
  PagesMap(name: string) {
    if (name == 'DialogPage') {
      DialogPage()
    }
  }

  build() {
    Navigation(this.pageStack) {
      Button('Push DialogPage')
        .margin(20)
        .width('80%')
        .onClick(() => {
          this.pageStack.pushPathByName('DialogPage', '');
        })
    }
    .mode(NavigationMode.Stack)
    .title('Main')
    .navDestination(this.PagesMap)
  }
}

@Component
export struct DialogPage {
  @Consume('NavPathStack') pageStack: NavPathStack;
  webContent: string =
    "<p>三月</p><p><img src=\"https://**.***.com/1539566909.gif\" title=\"1539566909.gif\" alt=\"0133e75674ca4332f8759f043f3536.gif\"/></p>"
  webContent2: string =
    `<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=no"><meta content="text/html;charset=UTF-8" http-equiv="Content-Type"/><meta content="no-cache,must-revalidate" http-equiv="Cache-Control"/><meta content="no-cache" http-equiv="pragma"/><meta content="0" http-equiv="expires"/><meta content="telephone=no, address=no" name="format-detection"/><meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/><meta name="apple-mobile-web-app-capable" content="yes"/><meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/><style type="text/css">body{max-width: 100%;padding:0; margin:0;font-size: 16px; color:#333; line-height:24px;}p{margin-top:5px;margin-bottom:5px;}a{color:blue;}img{max-width: 100%;}</style></head><body><p>今天吃什么,晒出你的午餐吧!!!</p></body></html>`
  controller: webview.WebviewController = new webview.WebviewController();
  build() {
    NavDestination() {
      Stack({ alignContent: Alignment.Center }) {
        Column() {
          // Text("Dialog NavDestination")
          // .fontSize(20)
          // .margin({ bottom: 100 })
          // Button("Close").onClick(() => {
          // this.pageStack.pop()
          // }).width('30%')

          Web({ src: '', controller: this.controller, renderMode: RenderMode.SYNC_RENDER })
            .layoutMode(WebLayoutMode.FIT_CONTENT)
            .onControllerAttached(() => {
              this.controller.loadData(this.webContent, "text/html", "UTF-8", 'https://**.***.com/v5_0/')
            })
        }
        .justifyContent(FlexAlign.Center)
        .backgroundColor(Color.White)
        .borderRadius(10)
        //.height('30%')
        //.width('80%')
      }.height("100%").width('100%')
      .backgroundColor('rgba(0,0,0,0.5)')
    }
    .backgroundColor('rgba(0,0,0,0.5)')
    .hideTitleBar(true)
    .mode(NavDestinationMode.DIALOG)
  }
}