wix网站建设,html样式模板,足彩彩票网站建设,做系统网站赚钱一、设置悬浮窗说明
悬浮窗可以在已有的任务基础上#xff0c;创建一个始终在前台显示的窗口。即使创建悬浮窗的任务退至后台#xff0c;悬浮窗仍然可以在前台显示。通常悬浮窗位于所有应用窗口之上#xff1b;开发者可以创建悬浮窗#xff0c;并对悬浮窗进行属性设置等操…一、设置悬浮窗说明
悬浮窗可以在已有的任务基础上创建一个始终在前台显示的窗口。即使创建悬浮窗的任务退至后台悬浮窗仍然可以在前台显示。通常悬浮窗位于所有应用窗口之上开发者可以创建悬浮窗并对悬浮窗进行属性设置等操作。
二、开发步骤
前提条件创建WindowType.TYPE_FLOAT即悬浮窗类型的窗口需要申请ohos.permission.SYSTEM_FLOAT_WINDOW权限。
1.创建悬浮窗。
通过window.createWindow接口创建悬浮窗类型的窗口。 2.对悬浮窗进行属性设置等操作。
悬浮窗窗口创建成功后可以改变其大小、位置等还可以根据应用需要设置悬浮窗背景色、亮度等属性。 3.加载显示悬浮窗的具体内容。
通过setUIContent和showWindow接口加载显示悬浮窗的具体内容。 4.销毁悬浮窗。
当不再需要悬浮窗时可根据具体实现逻辑使用destroyWindow接口销毁悬浮窗。
import UIAbility from ohos.app.ability.UIAbility;
import window from ohos.window;export default class EntryAbility extends UIAbility {onWindowStageCreate(windowStage) {// 1.创建悬浮窗。let windowClass null;let config {name: floatWindow, windowType: window.WindowType.TYPE_FLOAT, ctx: this.context};window.createWindow(config, (err, data) {if (err.code) {console.error(Failed to create the floatWindow. Cause: JSON.stringify(err));return;}console.info(Succeeded in creating the floatWindow. Data: JSON.stringify(data));windowClass data;// 2.悬浮窗窗口创建成功后设置悬浮窗的位置、大小及相关属性等。windowClass.moveWindowTo(300, 300, (err) {if (err.code) {console.error(Failed to move the window. Cause: JSON.stringify(err));return;}console.info(Succeeded in moving the window.);});windowClass.resize(500, 500, (err) {if (err.code) {console.error(Failed to change the window size. Cause: JSON.stringify(err));return;}console.info(Succeeded in changing the window size.);});// 3.为悬浮窗加载对应的目标页面。windowClass.setUIContent(pages/page4, (err) {if (err.code) {console.error(Failed to load the content. Cause: JSON.stringify(err));return;}console.info(Succeeded in loading the content.);// 3.显示悬浮窗。windowClass.showWindow((err) {if (err.code) {console.error(Failed to show the window. Cause: JSON.stringify(err));return;}console.info(Succeeded in showing the window.);});});// 4.销毁悬浮窗。当不再需要悬浮窗时可根据具体实现逻辑使用destroy对其进行销毁。windowClass.destroyWindow((err) {if (err.code) {console.error(Failed to destroy the window. Cause: JSON.stringify(err));return;}console.info(Succeeded in destroying the window.);});});}
};
本文主要参考HarmonyOS4.0官方开发文档整理