HarmonyOS page 半透明

请问下 page 如何改成半透明的背景色

HarmonyOS
2025-01-09 14:24:23
482浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
put_get

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")
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.

注意需要在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) ?? '');
});
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.

支持 NavDestination支持Dialog类型页面:

https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-navdestination-V5

NavDestinationMode.STANDARD: 标准类型NavDestination的生命周期

NavDestinationMode.DIALOG: 默认透明。

分享
微博
QQ
微信
回复
2025-01-09 17:28:43


相关问题
HarmonyOS 如何实现半透明Page
863浏览 • 1回复 待解决
HarmonyOS page页面如何设置半透明效果
729浏览 • 1回复 待解决
如何设置半透明页面
590浏览 • 1回复 待解决
HarmonyOS 如何设置页面背景半透明
744浏览 • 1回复 待解决
HarmonyOS 背景半透明渐变怎么设置
934浏览 • 1回复 待解决
HarmonyOS 如何实现半透明的遮罩效果
1008浏览 • 1回复 待解决
HarmonyOS 页面级的半透明可以如何实现
1223浏览 • 1回复 待解决
HarmonyOS page透明
483浏览 • 1回复 待解决
如何新开一个半透明的页面?
778浏览 • 1回复 待解决
HarmonyOS page和WebView无法设置为透明
1229浏览 • 1回复 待解决
HarmonyOS 如何将page设置为透明
767浏览 • 1回复 待解决
HarmonyOS 如何对page页面设置透明
1533浏览 • 1回复 待解决
stage模式下page页面透明化方法
905浏览 • 1回复 待解决