HarmonyOS 鸿蒙Next能不能设置一个Entry级别的页面完全透明?

HarmonyOS 鸿蒙Next能不能设置一个Entry级别的页面完全透明?

鸿蒙能不能设置一个Entry级别的页面完全透明?,怎么设置?(就像Android的Activity可以设置背景完全透明)

2 回复

主窗口规格是没有白色背景,但是也做不到完全透明,会有高斯模糊。子窗口设置窗口背景颜色为透明后为透明 

參考如下:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-V5

可以尝试直接在EntryAbility中添加onWindowStageCreate(windowStage: window.WindowStage): void { // Main window is created, set main page for this abilitydata.setWindowBackgroundColor(’#00ff33’) hilog.info(0x0000, ‘testTag’, ‘%{public}s’, ‘Ability onWindowStageCreate’); AppStorage.setAndLink(‘windowStage’, windowStage);//

可以在初始化的时候将this作为变量传入

import promptAction from '[@ohos](/user/ohos).promptAction';

import axios, { AxiosError, AxiosResponse } from '[@ohos](/user/ohos)/axios';

let customDialogId = 0;

[@Builder](/user/Builder)

function customDialogBuilder() {

 Column() {

   Text('Custom dialog Message').fontSize(20)

   Row() {

     Button("确认").onClick(() => {

       promptAction.closeCustomDialog(0)

     })

     Blank().width(50)

     Button("取消").onClick(() => {

       promptAction.closeCustomDialog(customDialogId)

     })

   }

 }.height(200).padding(5)

}

export class AxiosApi {

 pThis: Object;

 constructor(pThis: Object) {

   this.pThis = pThis;

 }

 openCustomDialog() {

   promptAction.openCustomDialog({

     builder: customDialogBuilder.bind(this.pThis)

   }).then((dialogId: number) => {

     customDialogId = dialogId

   })

 }

 sendGet() {

   // 发送一个get请求

   axios<string, AxiosResponse<string>, null>({

     method: "get",

     url: 'https://www.huawei.com'

   }).then((res: AxiosResponse) => {

     console.info('[X] result:' + JSON.stringify(res.data));

     this.openCustomDialog()

   }).catch((error: AxiosError) => {

     console.error("[X]" + JSON.stringify(error));

     this.openCustomDialog()

   })

 }

}

import { AxiosApi } from './Axios';

[@Entry](/user/Entry)

[@Component](/user/Component)

struct Index {

 [@State](/user/State) message: string = 'Hello World';

 build() {

   Row() {

     Column() {

       Button(this.message)

         .fontSize(50)

         .fontWeight(FontWeight.Bold)

         .onClick(() => {

           let axiosApi = new AxiosApi(this);

           axiosApi.sendGet();

         })

     }

     .width('100%')

   }

   .height('100%')

 }

}


更多关于HarmonyOS 鸿蒙Next能不能设置一个Entry级别的页面完全透明?的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


HarmonyOS 鸿蒙Next可以设置Entry级别的页面完全透明,但实现方式并非直接设置页面的backgroundColor属性为透明。由于主窗口规格限制,直接设置根节点的backgroundColor为Color.Transparent或相关透明值可能无法达到完全透明效果,通常会带有高斯模糊。

要实现Entry级别页面的完全透明,可以考虑采用子窗口的方式。通过创建一个子窗口,并将其背景颜色设置为透明,可以实现类似的效果。具体实现步骤包括在EntryAbility中创建并保存WindowStage,然后在需要显示透明页面的地方创建子窗口,并设置其UI内容和背景颜色为透明。

需要注意的是,透明页面的实现可能受到系统限制和版本差异的影响,因此在实际开发中可能需要进行相应的适配和调整。

如果问题依旧没法解决请联系官网客服,官网地址是:https://www.itying.com/category-93-b0.html

回到顶部