chinese直男口爆体育生外卖, 99久久er热在这里只有精品99, 又色又爽又黄18禁美女裸身无遮挡, gogogo高清免费观看日本电视,私密按摩师高清版在线,人妻视频毛茸茸,91论坛 兴趣闲谈,欧美 亚洲 精品 8区,国产精品久久久久精品免费

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

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

3天內(nèi)不再提示

harmony-utils之WindowUtil,窗口相關(guān)工具類

童長老 ? 來源:jf_14594073 ? 作者:jf_14594073 ? 2025-06-30 17:33 ? 次閱讀
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

harmony-utils之WindowUtil,窗口相關(guān)工具類

harmony-utils 簡介與說明


[harmony-utils] 一款功能豐富且極易上手的HarmonyOS工具庫,借助眾多實用工具類,致力于助力開發(fā)者迅速構(gòu)建鴻蒙應(yīng)用。其封裝的工具涵蓋了APP、設(shè)備、屏幕、授權(quán)、通知、線程間通信、彈框、吐司、生物認證、用戶首選項、拍照、相冊、掃碼、文件、日志,異常捕獲、字符、字符串、數(shù)字、集合、日期、隨機、base64、加密、解密、JSON等一系列的功能和操作,能夠滿足各種不同的開發(fā)需求。
[picker_utils] 是harmony-utils拆分出來的一個子庫,包含PickerUtil、PhotoHelper、ScanUtil。

下載安裝
ohpm i @pura/harmony-utils
ohpm i @pura/picker_utils

//全局初始化方法,在UIAbility的onCreate方法中初始化 AppUtil.init()
 onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
   AppUtil.init(this.context);
 }

API方法與使用


setPreferredOrientation 設(shè)置窗口的顯示方向?qū)傩?/h5>
WindowUtil.setPreferredOrientation(window.Orientation.LANDSCAPE).then(() = > {
  ToastUtil.showToast(`設(shè)置成功!`)
}).catch((err: BusinessError) = > {
  LogUtil.error(err);
});
getPreferredOrientation 獲取窗口的顯示方向?qū)傩?,主窗口調(diào)用
let orientation = WindowUtil.getPreferredOrientation();
 DialogHelper.showToast(`窗口屏幕方向:${orientation}`);
setWindowPrivacyMode 設(shè)置窗口是否為隱私模式。設(shè)置為隱私模式的窗口,窗口內(nèi)容將無法被截屏或錄屏
WindowUtil.setWindowPrivacyMode(true).then(() = > {
  ToastUtil.showToast("您已設(shè)置隱私模式,禁止截屏、錄像");
}).catch((err: BusinessError) = > {
  LogUtil.error(err);
});
isPrivacyMode 窗口是否隱私模式,默認主窗口
let isPrivacyMode = WindowUtil.isPrivacyMode();
 ToastUtil.showToast(`窗口是否隱私模式:${isPrivacyMode}`);
setWindowLayoutFullScreen 設(shè)置窗口的布局是否為沉浸式布局(該沉浸式布局狀態(tài)欄、導航欄仍然顯示)
WindowUtil.setWindowLayoutFullScreen(true).then(() = > {
  ToastUtil.showToast(`沉浸式布局已設(shè)置成功!`);
}).catch((err: BusinessError) = > {
  LogUtil.error(err);
});
isLayoutFullScreen 判斷窗口是否為沉浸式,默認主窗口
let isLayoutFullScreen = WindowUtil.isLayoutFullScreen();
 ToastUtil.showToast(`窗口是否為沉浸式:${isLayoutFullScreen}`);
setWindowSystemBarProperties 設(shè)置主窗口三鍵導航欄、狀態(tài)欄的屬性
WindowUtil.setWindowSystemBarProperties({
  statusBarColor: '#F00FF0',
  statusBarContentColor: '#0FF00F',
  isStatusBarLightIcon: true,
  navigationBarColor: '#F06060',
  navigationBarContentColor: "#0606F0",
  isNavigationBarLightIcon: true
}).then(() = > {
  ToastUtil.showToast("設(shè)置成功!");
}).catch((err: BusinessError) = > {
  LogUtil.error(err);
});
getWindowSystemBarProperties 獲取主窗口三鍵導航欄、狀態(tài)欄的屬性
let properties = WindowUtil.getWindowSystemBarProperties();
   let jsonStr = JSON.stringify(properties, null, 2);
setImmersiveModeEnabledState 設(shè)置當前窗口是否開啟沉浸式布局,該調(diào)用不會改變窗口模式和窗口大小
WindowUtil.setImmersiveModeEnabledState(true);
getImmersiveModeEnabledState 查詢當前窗口是否已經(jīng)開啟沉浸式布局
let enabled = WindowUtil.getImmersiveModeEnabledState();
  ToastUtil.showToast(`是否開啟沉浸式布局:${enabled}`);
setWindowGrayScale 設(shè)置窗口灰階。該接口需要在調(diào)用loadContent()或setUIContent()使窗口加載頁面內(nèi)容后調(diào)用。
WindowUtil.setWindowGrayScale(1.0);
setWindowBackgroundColor 設(shè)置窗口的背景色。Stage模型下,該接口需要在loadContent()或setUIContent()調(diào)用生效后使用
WindowUtil.setWindowBackgroundColor('#9932CC');
  ToastUtil.showToast("設(shè)置背景色成功!");
setWindowSystemBarEnable 設(shè)置主窗口三鍵導航欄、狀態(tài)欄、底部導航條的可見模式,狀態(tài)欄與底部導航條通過status控制、三鍵導航欄通過navigation控制
WindowUtil.setWindowSystemBarEnable(['status', 'navigation']).then(() = > {
  ToastUtil.showToast(`設(shè)置成功!`);
}).catch((err: BusinessError) = > {
  LogUtil.error(err);
});
setSpecificSystemBarEnabled 設(shè)置主窗口三鍵導航欄、狀態(tài)欄、底部導航條的顯示和隱藏
WindowUtil.setSpecificSystemBarEnabled('navigationIndicator', true).then(() = > {
  ToastUtil.showToast(`設(shè)置成功!`);
}).catch((err: BusinessError) = > {
  LogUtil.error(err);
});
setWindowKeepScreenOn 設(shè)置屏幕是否為常亮狀態(tài)
WindowUtil.setWindowKeepScreenOn(true).then(() = > {
  ToastUtil.showToast("你已設(shè)置常亮");
}).catch((err: BusinessError) = > {
  LogUtil.error(err);
});
isKeepScreenOn 屏幕是否常亮
let isKeepScreenOn = WindowUtil.isKeepScreenOn();
 ToastUtil.showToast(`屏幕是否常亮:${isKeepScreenOn}`);
setWindowBrightness 設(shè)置屏幕亮度值
WindowUtil.setWindowBrightness(0.7).then(() = > {
  ToastUtil.showToast(`您已設(shè)置亮度!`);
}).catch((err: BusinessError) = > {
  LogUtil.error(`異常信息-code: ${err.code} - msg: ${err.message}`)
});
getBrightness 獲取屏幕亮度。該參數(shù)為浮點數(shù),可設(shè)置的亮度范圍為[0.0, 1.0],其取1.0時表示最大亮度值。如果窗口沒有設(shè)置亮度值,表示亮度跟隨系統(tǒng),此時獲取到的亮度值為-1
let brightness = WindowUtil.getBrightness();
 ToastUtil.showToast(`屏幕亮度:${brightness}`);
setWindowFocusable 設(shè)置使用點擊或其他方式使該窗口獲焦的場景時,該窗口是否支持窗口焦點從點擊前的獲焦窗口切換到該窗口
WindowUtil.setWindowFocusable(true).then(() = > {
  ToastUtil.showToast("設(shè)置成功啦^·^");
}).catch((err: BusinessError) = > {
  ToastUtil.showToast("設(shè)置失??!");
});
isFocusable 窗口是否可聚焦,默認主窗口
let isFocusable = WindowUtil.isFocusable();
  ToastUtil.showToast(`窗口是否可聚焦:${isFocusable}`);
setWindowTouchable 設(shè)置窗口是否為可觸狀態(tài)
WindowUtil.setWindowTouchable(true).then(() = > {
  ToastUtil.showToast("設(shè)置成功啦^·^");
}).catch((err: BusinessError) = > {
  ToastUtil.showToast("設(shè)置失敗!");
});
isTouchable 窗口是否可觸摸,默認主窗口
let isTouchable = WindowUtil.isTouchable();
  ToastUtil.showToast(`窗口是否可觸摸:${isTouchable}`);
getWindowProperties 獲取當前窗口的屬性,默認主窗口
let properties = WindowUtil.getWindowProperties();
 let jsonStr = `${JSON.stringify(properties, null, 2)}`;
getWindowAvoidArea 獲取當前應(yīng)用窗口內(nèi)容規(guī)避的區(qū)域。如系統(tǒng)欄區(qū)域、劉海屏區(qū)域、手勢區(qū)域、軟鍵盤區(qū)域等與窗口內(nèi)容重疊時,需要窗口內(nèi)容避讓的區(qū)域
let area = WindowUtil.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM);
  let jsonStr = `${JSON.stringify(area, null, 2)}`;
getWindowType 獲取窗口類型,默認主窗口
let windowType = WindowUtil.getWindowType();
getWindowStatus 獲取當前應(yīng)用窗口的模式
let status = WindowUtil.getWindowStatus();
isFullScreen 判斷窗口是否全屏,默認主窗口
let isFullScreen = WindowUtil.isFullScreen();
isFocused 判斷當前窗口是否已獲焦
let isFocused = WindowUtil.isFocused();
isTransparent 窗口是否透明,默認主窗口
let isTransparent = WindowUtil.isTransparent();
isWindowShowing 判斷當前窗口是否已顯示,默認主窗口
let isWindowShowing = WindowUtil.isWindowShowing();
isWindowSupportWideGamut 判斷當前窗口是否支持廣色域模式,,默認主窗口
let isWindowSupportWideGamut = await WindowUtil.isWindowSupportWideGamut();
setDialogBackGestureEnabled 設(shè)置模態(tài)窗口是否響應(yīng)手勢返回事件,非模態(tài)窗口調(diào)用返回錯誤碼
WindowUtil.setDialogBackGestureEnabled(true).then(() = > {
  ToastUtil.showToast("設(shè)置成功啦^·^");
}).catch((err: BusinessError) = > {
  ToastUtil.showToast("設(shè)置失?。?);
});
setGestureBackEnabled 設(shè)置當前窗口是否禁用返回手勢功能,僅主窗全屏模式下生效,2in1設(shè)備下不生效。
let isGestureBack = WindowUtil.isGestureBackEnabled();
WindowUtil.setGestureBackEnabled(!isGestureBack).then(() = > {
  ToastUtil.showToast("設(shè)置成功啦^·^");
}).catch((err: BusinessError) = > {
  ToastUtil.showToast("設(shè)置失敗!");
});
isGestureBackEnabled 獲取當前窗口是否禁用返回手勢功能,僅主窗全屏模式下生效,2in1設(shè)備不生效。
let isGestureBack = WindowUtil.isGestureBackEnabled();
 ToastUtil.showToast(`當前窗口是否禁用返回:${isGestureBack}`);

創(chuàng)作不易,請給童長老點贊

審核編輯 黃宇

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學習之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報投訴
  • Harmony
    +關(guān)注

    關(guān)注

    0

    文章

    108

    瀏覽量

    3020
收藏 人收藏
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

    評論

    相關(guān)推薦
    熱點推薦

    harmony-utilsCacheUtil,緩存工具

    harmony-utilsCacheUtil,緩存工具
    的頭像 發(fā)表于 07-04 16:36 ?122次閱讀

    harmony-utilsCharUtil,字符工具

    harmony-utilsCharUtil,字符工具
    的頭像 發(fā)表于 07-04 16:34 ?126次閱讀

    harmony-utilsCrashUtil,異常相關(guān)工具

    harmony-utilsCrashUtil,異常相關(guān)工具
    的頭像 發(fā)表于 07-04 16:33 ?126次閱讀

    harmony-utilsDeviceUtil,設(shè)備相關(guān)工具

    harmony-utilsDeviceUtil,設(shè)備相關(guān)工具
    的頭像 發(fā)表于 07-03 18:27 ?162次閱讀

    harmony-utilsDisplayUtil,屏幕相關(guān)工具

    harmony-utilsDisplayUtil,屏幕相關(guān)工具
    的頭像 發(fā)表于 07-03 18:26 ?140次閱讀

    harmony-utilsEmitterUtil,Emitter工具

    harmony-utilsEmitterUtil,Emitter工具
    的頭像 發(fā)表于 07-03 18:24 ?140次閱讀

    harmony-utilsFileUtil,文件相關(guān)工具

    harmony-utilsFileUtil,文件相關(guān)工具
    的頭像 發(fā)表于 07-03 18:23 ?137次閱讀

    harmony-utilsFormatUtil,格式化工具

    harmony-utilsFormatUtil,格式化工具
    的頭像 發(fā)表于 07-03 18:22 ?141次閱讀

    harmony-utilsImageUtil,圖片相關(guān)工具

    harmony-utilsImageUtil,圖片相關(guān)工具
    的頭像 發(fā)表于 07-03 18:22 ?172次閱讀

    harmony-utilsLocationUtil,定位相關(guān)工具

    harmony-utilsLocationUtil,定位相關(guān)工具 harmony-utils
    的頭像 發(fā)表于 07-03 18:13 ?145次閱讀

    harmony-utilsPreviewUtil,文件預(yù)覽工具

    harmony-utilsPreviewUtil,文件預(yù)覽工具 harmony-utils 簡介與說明 [
    的頭像 發(fā)表于 07-03 11:40 ?122次閱讀

    harmony-utilsSnapshotUtil,截圖相關(guān)工具

    harmony-utilsSnapshotUtil,截圖相關(guān)工具 harmony-utils
    的頭像 發(fā)表于 07-03 11:36 ?118次閱讀

    harmony-utilsAuthUtil,生物認證相關(guān)工具

    # harmony-utilsAuthUtil,生物認證相關(guān)工具 ## harmony-utils
    的頭像 發(fā)表于 06-26 17:43 ?110次閱讀

    harmony-utilsNetworkUtil,網(wǎng)絡(luò)相關(guān)工具

    harmony-utilsNetworkUtil,網(wǎng)絡(luò)相關(guān)工具 harmony-utils
    的頭像 發(fā)表于 06-25 23:46 ?52次閱讀

    harmony-utilsDateUtil,日期工具

    harmony-utilsDateUtil,日期工具
    的頭像 發(fā)表于 06-25 22:15 ?61次閱讀