你可以参考以下步骤和demo:1、在module.json5文件中声明需要使用的 ohos.permission.PRIVACY_WINDOW 权限,参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides..."requestPermissions": [ { "name": "ohos.permission.PRIVACY_WINDOW" } ]2.示例代码// windowUtils.ets import window from '@ohos.window'; import common from '@ohos.app.ability.common'; export class windowUtils { static setWindowPrivacyModeInPage(context: common.UIAbilityContext,isFlag: boolean) { window.getLastWindow(context).then((lastWindow)=>{ lastWindow.setWindowPrivacyMode(isFlag); }) } } //页面 import common from '@ohos.app.ability.common'; import { windowUtils } from '../common/windowUtils'; @Entry @Component struct Index3 { @State message: string = 'Hello World'; onPageShow(): void { windowUtils.setWindowPrivacyModeInPage(getContext(this) as common.UIAbilityContext, true); } onPageHide() { windowUtils.setWindowPrivacyModeInPage(getContext(this) as common.UIAbilityContext,false); } build() { Row() { Column() { Text(this.message) .fontSize(50) .fontWeight(FontWeight.Bold) } .width('100%') } .height('100%') } } 本文参与了 【 HarmonyOS NEXT 技术问答冲榜,等你来战!】欢迎正在阅读的你也加入。
你可以参考以下步骤和demo:
1、在module.json5文件中声明需要使用的 ohos.permission.PRIVACY_WINDOW 权限,参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides...
2.示例代码
本文参与了 【 HarmonyOS NEXT 技术问答冲榜,等你来战!】欢迎正在阅读的你也加入。