【关键字】
window / setWindowBackgroundColor / 窗口背景 / 透明 / 崩溃
【问题描述】
使用@ohos.window的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);
}
})
})
【解决方案】
setWindowBackgroundColor接口需要在loadContent()或setUIContent()调用生效后使用。
文章讲述了在使用HuaweiHarmonyOS的setWindowBackgroundColor接口设置窗口背景透明时,可能导致窗口无法显示并崩溃的问题。解决方法是确保在loadContent()或setUIContent()函数之后调用该接口。
6939

被折叠的 条评论
为什么被折叠?



