<acronym id="s8ci2"><small id="s8ci2"></small></acronym>
<rt id="s8ci2"></rt><rt id="s8ci2"><optgroup id="s8ci2"></optgroup></rt>
<acronym id="s8ci2"></acronym>
<acronym id="s8ci2"><center id="s8ci2"></center></acronym>
0
  • 聊天消息
  • 系統消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發帖/加入社區
創作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示

鴻蒙OS元服務開發:【(Stage模型)設置懸浮窗】

jf_46214456 ? 來源:jf_46214456 ? 作者:jf_46214456 ? 2024-04-03 15:32 ? 次閱讀

一、設置懸浮窗說明

懸浮窗可以在已有的任務基礎上,創建一個始終在前臺顯示的窗口。即使創建懸浮窗的任務退至后臺,懸浮窗仍然可以在前臺顯示。通常懸浮窗位于所有應用窗口之上;開發者可以創建懸浮窗,并對懸浮窗進行屬性設置等操作。

二、開發步驟

前提條件:創建WindowType.TYPE_FLOAT即懸浮窗類型的窗口,需要申請ohos.permission.SYSTEM_FLOAT_WINDOW權限。

1.創建懸浮窗。

通過window.createWindow接口創建懸浮窗類型的窗口。

2.對懸浮窗進行屬性設置等操作。

懸浮窗窗口創建成功后,可以改變其大小、位置等,還可以根據應用需要設置懸浮窗背景色、亮度等屬性。

3.加載顯示懸浮窗的具體內容。

通過setUIContent和showWindow接口加載顯示懸浮窗的具體內容。

4.銷毀懸浮窗。

當不再需要懸浮窗時,可根據具體實現邏輯,使用destroyWindow接口銷毀懸浮窗。
更多鴻蒙開發技術已更新↓

搜狗高速瀏覽器截圖20240326151547.png

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.');
});
});
}
};


審核編輯 黃宇

聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網站授權轉載。文章觀點僅代表作者本人,不代表電子發燒友網立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規問題,請聯系本站處理。 舉報投訴
  • 模型
    +關注

    關注

    1

    文章

    2750

    瀏覽量

    47807
  • 鴻蒙
    +關注

    關注

    55

    文章

    1786

    瀏覽量

    42158
  • 鴻蒙OS
    +關注

    關注

    0

    文章

    156

    瀏覽量

    4290
收藏 人收藏

    評論

    相關推薦

    鴻蒙Stage模型--概述

    Stage模型:HarmonyOS 3.1 Develper Preview版本開始新增的模型,是目前主推且會長期演進的模型。在該模型中,由
    的頭像 發表于 01-29 13:59 ?753次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>Stage</b><b class='flag-5'>模型</b>--概述

    Stage 模型深入解讀

    跨設備的遷移和協同機制。本文為大家詳細介紹 Stage 模型。 一、Stage 模型概念 應用開發模型
    的頭像 發表于 02-18 09:28 ?510次閱讀
    <b class='flag-5'>Stage</b> <b class='flag-5'>模型</b>深入解讀

    鴻蒙OS開發實例:【手擼服務卡片】

    服務卡片指導文檔位于“**開發/應用模型/Stage模型開發指導/
    的頭像 發表于 03-28 22:11 ?757次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>OS</b><b class='flag-5'>開發</b>實例:【手擼<b class='flag-5'>服務</b>卡片】

    鴻蒙應用/服務開發-窗口(Stage模型設置懸浮

    一、設置懸浮說明 懸浮可以在已有的任務基礎上,創建一個始終在前臺顯示的窗口。即使創建懸浮
    發表于 02-04 14:05

    鴻蒙應用/服務開發-窗口(Stage模型設置應用主窗口

    一、 設置應用主窗口****說明 在Stage模型下,應用主窗口由UIAbility創建并維護生命周期。在UIAbility的onWindowStageCreate回調中,通過WindowStage
    發表于 02-05 14:45

    Stage模型深入解讀

    的遷移和協同機制。本文為大家詳細介紹Stage模型。 一、Stage模型概念 應用開發模型是運行
    發表于 03-15 10:32

    鴻蒙服務萬能卡片開發-stage模型和fa模型的卡片區別

    一、項目類型 Application: 應用開發 Atomic Service:原子化服務開發 這里選擇Empty Ability模板創建項目。 二、Stage
    發表于 05-22 14:20

    鴻蒙原生應用/服務開發-Stage模型能力接口(一)

    從API version 9 開始支持。后續版本的新增接口,采用上角標單獨標記接口的起始版本。本模塊接口僅可在Stage模型下使用。二、導入模塊 .import Ability from
    發表于 12-08 16:34

    鴻蒙原生應用/服務開發-Stage模型能力接口(二)

    退出原因、遷移結果、窗口類型等。本模塊首批接口從API version 9開始支持。后續版本的新增接口,采用上角標單獨標記接口的起始版本。本模塊接口僅可在Stage模型下使用。二、導入模塊
    發表于 12-11 14:48

    鴻蒙原生應用/服務開發-Stage模型能力接口(四)

    API version 9 開始支持。后續版本的新增接口,采用上角標單獨標記接口的起始版本。本模塊接口僅可在Stage模型下使用。 二、導入模塊 import AbilityStage from
    發表于 12-14 15:39

    鴻蒙原生應用/服務開發-Stage模型能力接口(五)

    Stage模型下使用 二、 導入模塊 import common from \'@ohos.app.ability.common\'; 三、系統能力 :以下各項對應的系統能力均為
    發表于 12-15 15:11

    鴻蒙原生應用/服務開發-Stage模型能力接口(六)

    的起始版本。本模塊接口僅可在Stage模型下使用。 二、 導入模塊 import contextConstant from \'@ohos.app.ability.contextConstant\'; 三
    發表于 12-18 14:40

    鴻蒙原生應用/服務開發-Stage模型能力接口(七)

    接口的起始版本。本模塊接口僅可在Stage模型下使用。 二、導入模塊 import EnvironmentCallback from
    發表于 12-19 11:03

    鴻蒙原生應用/服務開發-Stage模型能力接口(八)

    獨標記接口的起始版本。本模塊接口僅可在Stage模型下使用。 二、導入模塊 .import ExtensionAbility from
    發表于 12-20 16:12

    Stage模型深入解讀

    形態下統一的應用組件生命周期,并支持跨設備的遷移和協同機制。本文為大家詳細介紹Stage模型。 一 Stage模型概念 應用開發
    的頭像 發表于 03-16 13:35 ?607次閱讀
    亚洲欧美日韩精品久久_久久精品AⅤ无码中文_日本中文字幕有码在线播放_亚洲视频高清不卡在线观看
    <acronym id="s8ci2"><small id="s8ci2"></small></acronym>
    <rt id="s8ci2"></rt><rt id="s8ci2"><optgroup id="s8ci2"></optgroup></rt>
    <acronym id="s8ci2"></acronym>
    <acronym id="s8ci2"><center id="s8ci2"></center></acronym>