HarmonyOS鸿蒙最全鸿蒙HarmonyOS实战-窗口管理_鸿蒙nativewindow 获取窗口(1),吊打面试官

img
img

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  1. 弹出式对话框:用于显示警告、提示、确认等信息,请求用户的输入或进行操作确认。
  2. 工具窗口:用于显示一些辅助工具,例如调色板、图层面板等,在用户需要时进行操作。
  3. 标签页:用于在主窗口内切换和显示不同的内容,例如浏览器的多个标签页。
  4. 拆分窗口:将主窗口分割成多个子窗口,用于同时显示多个相关的内容,例如文本编辑器的分屏编辑功能。

应用子窗口可以提高用户的操作效率和便利性,使界面更加灵活和功能更加丰富。但在设计和使用时需要注意合理使用,避免过多的窗口导致用户的混乱和困惑。

import UIAbility from ‘@ohos.app.ability.UIAbility’;

let windowStage_ = null;
let sub_windowClass = null;
export default class EntryAbility extends UIAbility {
showSubWindow() {
// 1.创建应用子窗口。
windowStage_.createSubWindow(“mySubWindow”, (err, data) => {
if (err.code) {
console.error('Failed to create the subwindow. Cause: ’ + JSON.stringify(err));
return;
}
sub_windowClass = data;
console.info('Succeeded in creating the subwindow. Data: ’ + JSON.stringify(data));
// 2.子窗口创建成功后,设置子窗口的位置、大小及相关属性等。
sub_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.’);
});
sub_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.为子窗口加载对应的目标页面。
sub_windowClass.setUIContent(“pages/page3”, (err) => {
if (err.code) {
console.error(‘Failed to load the content. Cause:’ + JSON.stringify(err));
return;
}
console.info(‘Succeeded in loading the content.’);
// 3.显示子窗口。
sub_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.’);
});
});
})
}

destroySubWindow() {
// 4.销毁子窗口。当不再需要子窗口时,可根据具体实现逻辑,使用destroy对其进行销毁。
sub_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.’);
});
}

onWindowStageCreate(windowStage) {
windowStage_ = windowStage;
// 开发者可以在适当的时机,如主窗口上按钮点击事件等,创建子窗口。并不一定需要在onWindowStageCreate调用,这里仅作展示
this.showSubWindow();
}

onWindowStageDestroy() {
// 开发者可以在适当的时机,如子窗口上点击关闭按钮等,销毁子窗口。并不一定需要在onWindowStageDestroy调用,这里仅作展示
this.destroySubWindow();
}
};

☀️2.3.3 体验窗口沉浸式能力

概念上面有介绍,就不多说了。

import UIAbility from ‘@ohos.app.ability.UIAbility’;

export default class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage) {
// 1.获取应用主窗口。
let windowClass = null;
windowStage.getMainWindow((err, data) => {
if (err.code) {
console.error('Failed to obtain the main window. Cause: ’ + JSON.stringify(err));
return;
}
windowClass = data;
console.info('Succeeded in obtaining the main window. Data: ’ + JSON.stringify(data));

// 2.实现沉浸式效果:设置导航栏、状态栏不显示。
let names = [];
windowClass.setWindowSystemBarEnable(names, (err) => {
if (err.code) {
console.error(‘Failed to set the system bar to be visible. Cause:’ + JSON.stringify(err));
return;
}
console.info(‘Succeeded in setting the system bar to be visible.’);
});
})
// 3.为沉浸式窗口加载对应的目标页面。
windowStage.loadContent(“pages/page2”, (err) => {
if (err.code) {
console.error(‘Failed to load the content. Cause:’ + JSON.stringify(err));
return;
}
console.info(‘Succeeded in loading the content.’);
});
}
};

在这里插入图片描述

☀️2.3.4 设置悬浮窗

概念上面有介绍,就不多说了。

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

最后,有很多小伙伴不知道学习哪些鸿蒙开发技术?不知道需要重点掌握哪些鸿蒙应用开发知识点?而且学习时频繁踩坑,最终浪费大量时间。所以有一份实用的鸿蒙(HarmonyOS NEXT)资料用来跟着学习是非常有必要的。

这份鸿蒙(HarmonyOS NEXT)资料包含了鸿蒙开发必掌握的核心知识要点,内容包含了(**ArkTS、ArkUI开发组件、Stage模型、多端部署、分布式应用开发、音频、视频、WebGL、OpenHarmony****多媒体技术、Napi组件、OpenHarmony内核、Harmony南向开发、鸿蒙项目实战等等)鸿蒙(HarmonyOS NEXT)**技术知识点。

希望这一份鸿蒙学习资料能够给大家带来帮助,有需要的小伙伴自行领取,限时开源,先到先得~无套路领取!!

如果你是一名有经验的资深Android移动开发、Java开发、前端开发、对鸿蒙感兴趣以及转行人员,可以直接领取这份资料

获取这份完整版高清学习路线,请点击→纯血版全套鸿蒙HarmonyOS学习资料****

鸿蒙(HarmonyOS NEXT)最新学习路线

  • HarmonOS基础技能

  • HarmonOS就业必备技能 
  • HarmonOS多媒体技术

  • 鸿蒙NaPi组件进阶

  • HarmonOS高级技能

  • 初识HarmonOS内核
  • 实战就业级设备开发

有了路线图,怎么能没有学习资料呢,小编也准备了一份联合鸿蒙官方发布笔记整理收纳的一套系统性的鸿蒙(OpenHarmony )学习手册(共计1236页)鸿蒙(OpenHarmony )开发入门教学视频,内容包含:ArkTS、ArkUI、Web开发、应用模型、资源分类…等知识点。

获取以上完整版高清学习路线,请点击→纯血版全套鸿蒙HarmonyOS学习资料

《鸿蒙 (OpenHarmony)开发入门教学视频》

《鸿蒙生态应用开发V2.0白皮书》

图片

《鸿蒙 (OpenHarmony)开发基础到实战手册》

OpenHarmony北向、南向开发环境搭建

图片

《鸿蒙开发基础》
  • ArkTS语言
  • 安装DevEco Studio
  • 运用你的第一个ArkTS应用
  • ArkUI声明式UI开发
  • .……

图片

《鸿蒙开发进阶》
  • Stage模型入门
  • 网络管理
  • 数据管理
  • 电话服务
  • 分布式应用开发
  • 通知与窗口管理
  • 多媒体技术
  • 安全技能
  • 任务管理
  • WebGL
  • 国际化开发
  • 应用测试
  • DFX面向未来设计
  • 鸿蒙系统移植和裁剪定制
  • ……

图片

《鸿蒙进阶实战》
  • ArkTS实践
  • UIAbility应用

深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!


img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上鸿蒙开发知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

需要这份系统化的资料的朋友,可以戳这里获取

259a5ffe804fa6d0db.png)
[外链图片转存中…(img-fPLNd2pB-1715181501427)]
[外链图片转存中…(img-TB41xqGI-1715181501427)]

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上鸿蒙开发知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

需要这份系统化的资料的朋友,可以戳这里获取

  • 25
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值