中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
在DevEco Studio和系统升级前,在EntryAbility.ets文件可以创建悬浮窗,升级到最新的之后创建失败。代码如下:
let floatWindowClass: window.Window | null = null; // 1.创建悬浮窗 const config: window.Configuration = { name: "floatWindow", windowType: window.WindowType.TYPE_FLOAT, ctx: this.context }; window.createWindow(config, (err: BusinessError, data) => { let errCode: number = err.code; if (errCode) { console.error('floatWindowClass Failed to create the floatWindow. Cause: ' + JSON.stringify(err)); return; } console.info('floatWindowClass Succeeded in creating the floatWindow. Data: ' + JSON.stringify(data)); { let errCode: number = err.code; if (errCode) { console.error('floatWindowClass Failed to create the floatWindow. Cause: ' + JSON.stringify(err)); return; } console.info('floatWindowClass Succeeded in creating the floatWindow. Data: ' + JSON.stringify(data)); floatWindowClass = data; AppStorage.setOrCreate('floatWindowClass', floatWindowClass); // 2.悬浮窗窗口创建成功后,设置悬浮窗的位置、大小及相关属性等。 floatWindowClass.moveWindowTo(0, 604, (err: BusinessError) => { let errCode: number = err.code; if (errCode) { console.error('floatWindowClass Failed to move the window. Cause:' + JSON.stringify(err)); return; } console.info('floatWindowClass Succeeded in moving the window.'); }); // 3.为悬浮窗加载对应的目标页面。 floatWindowClass.setUIContent("pages/view/AudioComponent", (err: BusinessError) => { let errCode: number = err.code; if (errCode) { console.error('floatWindowClass Failed to load the content. Cause:' + JSON.stringify(err)); return; } console.info('floatWindowClass Succeeded in loading the content.'); }); floatWindowClass.on('windowEvent', (data) => { EmitterUtils.sendEvent(EmitterEventId.AUDIO_WINDOW_TYPE, data) }); })
微信扫码分享