@ohos.window 的API 【findWindow】与【setWindowBackgroundColor】设置窗口透明背景颜色导致窗口不显示

在调用窗口展示的时设置窗口背景透明,会偶现窗口不暂时,并且会有崩溃现象发生,崩溃日志指向【setWindowBackgroundColor】方法。代码示例如下:

let dialogConfig: window.Configuration = {  
  name: 'webKeyboard',  
  ctx: getContext(this),  
  windowType: window.WindowType.TYPE_DIALOG  
}  
  
window.createWindow(dialogConfig, (err, win) => {  
  win.resize(this.deviceInfo.width, this.deviceInfo.height);  
  win.moveWindowTo(0, 0)  
  win.setUIContent(path);  
  
  win.showWindow((err) => {  
    if (err.code) {  
      // console.error('Failed to show the window. Cause: ' + JSON.stringify(err));  
    }else {  
      // console.info('Succeeded in showing the window.');  
      let windowClass: window.Window = window.findWindow("webKeyboard");  
      windowClass.setWindowBackgroundColor('#00000000')  
      windowClass.setWindowTouchable(true);  
    }  
  
  })  
})
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
HarmonyOS
2024-09-23 11:55:37
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
put_get

该接口需要在loadContent()或setUIContent()调用生效后使用。参考文档:https://docs.openharmony.cn/pages/v4.0/zh-cn/application-dev/reference/apis/js-apis-window.md/#setwindowbackgroundcolor9

分享
微博
QQ
微信
回复
2024-09-23 18:07:35
相关问题
如何设置窗口背景颜色
911浏览 • 1回复 待解决
HarmonyOS window.findWindow获取子窗口错误
1178浏览 • 1回复 待解决
如何设置窗口背景
2596浏览 • 1回复 待解决
如何将背景颜色设置透明
3612浏览 • 1回复 待解决
设置窗口透明度未生效
2223浏览 • 1回复 待解决
Window窗口生命周期问题
1127浏览 • 1回复 待解决
如何获取主窗口window宽度
2980浏览 • 1回复 待解决
如何获取当前window窗口方向
1093浏览 • 1回复 待解决
HarmonyOS api10如何给子窗口设置圆角
1159浏览 • 1回复 待解决