女人自慰AV免费观看内涵网,日韩国产剧情在线观看网址,神马电影网特片网,最新一级电影欧美,在线观看亚洲欧美日韩,黄色视频在线播放免费观看,ABO涨奶期羡澄,第一导航fulione,美女主播操b

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

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

3天內不再提示

harmony-utils之WindowUtil,窗口相關工具類

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

掃碼添加小助手

加入工程師交流群

harmony-utils之WindowUtil,窗口相關工具類

harmony-utils 簡介與說明


[harmony-utils] 一款功能豐富且極易上手的HarmonyOS工具庫,借助眾多實用工具類,致力于助力開發者迅速構建鴻蒙應用。其封裝的工具涵蓋了APP、設備、屏幕、授權、通知、線程間通信、彈框、吐司、生物認證、用戶首選項、拍照、相冊、掃碼、文件、日志,異常捕獲、字符、字符串、數字、集合、日期、隨機、base64、加密、解密、JSON等一系列的功能和操作,能夠滿足各種不同的開發需求。
[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 設置窗口的顯示方向屬性
WindowUtil.setPreferredOrientation(window.Orientation.LANDSCAPE).then(() = > {
  ToastUtil.showToast(`設置成功!`)
}).catch((err: BusinessError) = > {
  LogUtil.error(err);
});
getPreferredOrientation 獲取窗口的顯示方向屬性,主窗口調用
let orientation = WindowUtil.getPreferredOrientation();
 DialogHelper.showToast(`窗口屏幕方向:${orientation}`);
setWindowPrivacyMode 設置窗口是否為隱私模式。設置為隱私模式的窗口,窗口內容將無法被截屏或錄屏
WindowUtil.setWindowPrivacyMode(true).then(() = > {
  ToastUtil.showToast("您已設置隱私模式,禁止截屏、錄像");
}).catch((err: BusinessError) = > {
  LogUtil.error(err);
});
isPrivacyMode 窗口是否隱私模式,默認主窗口
let isPrivacyMode = WindowUtil.isPrivacyMode();
 ToastUtil.showToast(`窗口是否隱私模式:${isPrivacyMode}`);
setWindowLayoutFullScreen 設置窗口的布局是否為沉浸式布局(該沉浸式布局狀態欄、導航欄仍然顯示)
WindowUtil.setWindowLayoutFullScreen(true).then(() = > {
  ToastUtil.showToast(`沉浸式布局已設置成功!`);
}).catch((err: BusinessError) = > {
  LogUtil.error(err);
});
isLayoutFullScreen 判斷窗口是否為沉浸式,默認主窗口
let isLayoutFullScreen = WindowUtil.isLayoutFullScreen();
 ToastUtil.showToast(`窗口是否為沉浸式:${isLayoutFullScreen}`);
setWindowSystemBarProperties 設置主窗口三鍵導航欄、狀態欄的屬性
WindowUtil.setWindowSystemBarProperties({
  statusBarColor: '#F00FF0',
  statusBarContentColor: '#0FF00F',
  isStatusBarLightIcon: true,
  navigationBarColor: '#F06060',
  navigationBarContentColor: "#0606F0",
  isNavigationBarLightIcon: true
}).then(() = > {
  ToastUtil.showToast("設置成功!");
}).catch((err: BusinessError) = > {
  LogUtil.error(err);
});
getWindowSystemBarProperties 獲取主窗口三鍵導航欄、狀態欄的屬性
let properties = WindowUtil.getWindowSystemBarProperties();
   let jsonStr = JSON.stringify(properties, null, 2);
setImmersiveModeEnabledState 設置當前窗口是否開啟沉浸式布局,該調用不會改變窗口模式和窗口大小
WindowUtil.setImmersiveModeEnabledState(true);
getImmersiveModeEnabledState 查詢當前窗口是否已經開啟沉浸式布局
let enabled = WindowUtil.getImmersiveModeEnabledState();
  ToastUtil.showToast(`是否開啟沉浸式布局:${enabled}`);
setWindowGrayScale 設置窗口灰階。該接口需要在調用loadContent()或setUIContent()使窗口加載頁面內容后調用。
WindowUtil.setWindowGrayScale(1.0);
setWindowBackgroundColor 設置窗口的背景色。Stage模型下,該接口需要在loadContent()或setUIContent()調用生效后使用
WindowUtil.setWindowBackgroundColor('#9932CC');
  ToastUtil.showToast("設置背景色成功!");
setWindowSystemBarEnable 設置主窗口三鍵導航欄、狀態欄、底部導航條的可見模式,狀態欄與底部導航條通過status控制、三鍵導航欄通過navigation控制
WindowUtil.setWindowSystemBarEnable(['status', 'navigation']).then(() = > {
  ToastUtil.showToast(`設置成功!`);
}).catch((err: BusinessError) = > {
  LogUtil.error(err);
});
setSpecificSystemBarEnabled 設置主窗口三鍵導航欄、狀態欄、底部導航條的顯示和隱藏
WindowUtil.setSpecificSystemBarEnabled('navigationIndicator', true).then(() = > {
  ToastUtil.showToast(`設置成功!`);
}).catch((err: BusinessError) = > {
  LogUtil.error(err);
});
setWindowKeepScreenOn 設置屏幕是否為常亮狀態
WindowUtil.setWindowKeepScreenOn(true).then(() = > {
  ToastUtil.showToast("你已設置常亮");
}).catch((err: BusinessError) = > {
  LogUtil.error(err);
});
isKeepScreenOn 屏幕是否常亮
let isKeepScreenOn = WindowUtil.isKeepScreenOn();
 ToastUtil.showToast(`屏幕是否常亮:${isKeepScreenOn}`);
setWindowBrightness 設置屏幕亮度值
WindowUtil.setWindowBrightness(0.7).then(() = > {
  ToastUtil.showToast(`您已設置亮度!`);
}).catch((err: BusinessError) = > {
  LogUtil.error(`異常信息-code: ${err.code} - msg: ${err.message}`)
});
getBrightness 獲取屏幕亮度。該參數為浮點數,可設置的亮度范圍為[0.0, 1.0],其取1.0時表示最大亮度值。如果窗口沒有設置亮度值,表示亮度跟隨系統,此時獲取到的亮度值為-1
let brightness = WindowUtil.getBrightness();
 ToastUtil.showToast(`屏幕亮度:${brightness}`);
setWindowFocusable 設置使用點擊或其他方式使該窗口獲焦的場景時,該窗口是否支持窗口焦點從點擊前的獲焦窗口切換到該窗口
WindowUtil.setWindowFocusable(true).then(() = > {
  ToastUtil.showToast("設置成功啦^·^");
}).catch((err: BusinessError) = > {
  ToastUtil.showToast("設置失敗!");
});
isFocusable 窗口是否可聚焦,默認主窗口
let isFocusable = WindowUtil.isFocusable();
  ToastUtil.showToast(`窗口是否可聚焦:${isFocusable}`);
setWindowTouchable 設置窗口是否為可觸狀態
WindowUtil.setWindowTouchable(true).then(() = > {
  ToastUtil.showToast("設置成功啦^·^");
}).catch((err: BusinessError) = > {
  ToastUtil.showToast("設置失敗!");
});
isTouchable 窗口是否可觸摸,默認主窗口
let isTouchable = WindowUtil.isTouchable();
  ToastUtil.showToast(`窗口是否可觸摸:${isTouchable}`);
getWindowProperties 獲取當前窗口的屬性,默認主窗口
let properties = WindowUtil.getWindowProperties();
 let jsonStr = `${JSON.stringify(properties, null, 2)}`;
getWindowAvoidArea 獲取當前應用窗口內容規避的區域。如系統欄區域、劉海屏區域、手勢區域、軟鍵盤區域等與窗口內容重疊時,需要窗口內容避讓的區域
let area = WindowUtil.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM);
  let jsonStr = `${JSON.stringify(area, null, 2)}`;
getWindowType 獲取窗口類型,默認主窗口
let windowType = WindowUtil.getWindowType();
getWindowStatus 獲取當前應用窗口的模式
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 設置模態窗口是否響應手勢返回事件,非模態窗口調用返回錯誤碼
WindowUtil.setDialogBackGestureEnabled(true).then(() = > {
  ToastUtil.showToast("設置成功啦^·^");
}).catch((err: BusinessError) = > {
  ToastUtil.showToast("設置失敗!");
});
setGestureBackEnabled 設置當前窗口是否禁用返回手勢功能,僅主窗全屏模式下生效,2in1設備下不生效。
let isGestureBack = WindowUtil.isGestureBackEnabled();
WindowUtil.setGestureBackEnabled(!isGestureBack).then(() = > {
  ToastUtil.showToast("設置成功啦^·^");
}).catch((err: BusinessError) = > {
  ToastUtil.showToast("設置失敗!");
});
isGestureBackEnabled 獲取當前窗口是否禁用返回手勢功能,僅主窗全屏模式下生效,2in1設備不生效。
let isGestureBack = WindowUtil.isGestureBackEnabled();
 ToastUtil.showToast(`當前窗口是否禁用返回:${isGestureBack}`);

創作不易,請給童長老點贊

審核編輯 黃宇

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

    關注

    0

    文章

    108

    瀏覽量

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

掃碼添加小助手

加入工程師交流群

    評論

    相關推薦
    熱點推薦

    harmony-utilsCacheUtil,緩存工具

    harmony-utilsCacheUtil,緩存工具
    的頭像 發表于 07-04 16:36 ?114次閱讀

    harmony-utilsCharUtil,字符工具

    harmony-utilsCharUtil,字符工具
    的頭像 發表于 07-04 16:34 ?118次閱讀

    harmony-utilsCrashUtil,異常相關工具

    harmony-utilsCrashUtil,異常相關工具
    的頭像 發表于 07-04 16:33 ?117次閱讀

    harmony-utilsDeviceUtil,設備相關工具

    harmony-utilsDeviceUtil,設備相關工具
    的頭像 發表于 07-03 18:27 ?152次閱讀

    harmony-utilsDisplayUtil,屏幕相關工具

    harmony-utilsDisplayUtil,屏幕相關工具
    的頭像 發表于 07-03 18:26 ?126次閱讀

    harmony-utilsEmitterUtil,Emitter工具

    harmony-utilsEmitterUtil,Emitter工具
    的頭像 發表于 07-03 18:24 ?130次閱讀

    harmony-utilsFileUtil,文件相關工具

    harmony-utilsFileUtil,文件相關工具
    的頭像 發表于 07-03 18:23 ?129次閱讀

    harmony-utilsFormatUtil,格式化工具

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

    harmony-utilsImageUtil,圖片相關工具

    harmony-utilsImageUtil,圖片相關工具
    的頭像 發表于 07-03 18:22 ?164次閱讀

    harmony-utilsLocationUtil,定位相關工具

    harmony-utilsLocationUtil,定位相關工具 harmony-utils
    的頭像 發表于 07-03 18:13 ?135次閱讀

    harmony-utilsPreviewUtil,文件預覽工具

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

    harmony-utilsSnapshotUtil,截圖相關工具

    harmony-utilsSnapshotUtil,截圖相關工具 harmony-utils
    的頭像 發表于 07-03 11:36 ?108次閱讀

    harmony-utilsAuthUtil,生物認證相關工具

    # harmony-utilsAuthUtil,生物認證相關工具 ## harmony-utils
    的頭像 發表于 06-26 17:43 ?104次閱讀

    harmony-utilsNetworkUtil,網絡相關工具

    harmony-utilsNetworkUtil,網絡相關工具 harmony-utils
    的頭像 發表于 06-25 23:46 ?48次閱讀

    harmony-utilsDateUtil,日期工具

    harmony-utilsDateUtil,日期工具
    的頭像 發表于 06-25 22:15 ?57次閱讀