在线观看www成人影院-在线观看www日本免费网站-在线观看www视频-在线观看操-欧美18在线-欧美1级

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

    文章

    75

    瀏覽量

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

掃碼添加小助手

加入工程師交流群

    評論

    相關推薦
    熱點推薦

    harmony-utilsToastUtil,吐司工具

    harmony-utilsToastUtil,吐司工具 harmony-utils 簡介與說明 [h
    的頭像 發表于 06-30 17:35 ?80次閱讀

    harmony-utilsTypeUtil,類型檢查工具

    harmony-utilsTypeUtil,類型檢查工具 harmony-utils 簡介與說明 [
    的頭像 發表于 06-30 17:35 ?73次閱讀

    harmony-utilsWantUtil,Want工具

    harmony-utilsWantUtil,Want工具 harmony-utils 簡介與說明 [
    的頭像 發表于 06-30 17:34 ?73次閱讀

    harmony-utilsBase64Util,Base64工具

    harmony-utilsBase64Util,Base64工具 harmony-utils 簡介與說明 [
    的頭像 發表于 06-30 17:32 ?80次閱讀

    harmony-utilsAES,AES加解密

    harmony-utilsAES,AES加解密 harmony-utils 簡介與說明 [harmony-utils] 一款功能豐富且極易上手的HarmonyOS
    的頭像 發表于 06-30 17:30 ?95次閱讀

    harmony-utilsDES,DES加解密

    harmony-utilsDES,DES加解密 harmony-utils 簡介與說明 [harmony-utils]一款功能豐富且極易上手的HarmonyOS
    的頭像 發表于 06-30 17:16 ?78次閱讀

    harmony-utilsRSA,RSA加解密

    harmony-utilsRSA,RSA加解密 harmony-utils 簡介與說明 [harmony-utils] 一款功能豐富且極易上手的HarmonyOS
    的頭像 發表于 06-30 16:52 ?66次閱讀

    harmony-utilsSHA,SHA工具

    harmony-utilsSHA,SHA工具 harmony-utils 簡介與說明 [harmon
    的頭像 發表于 06-30 16:51 ?99次閱讀

    harmony-utilsMD5,MD5工具

    harmony-utilsMD5,MD5工具 harmony-utils 簡介與說明 [harmon
    的頭像 發表于 06-30 16:49 ?107次閱讀

    harmony-utilsSM3,SM3工具

    harmony-utilsSM3,SM3工具 harmony-utils 簡介與說明 harmony
    的頭像 發表于 06-28 18:37 ?103次閱讀

    harmony-utilsPickerUtil,拍照、文件選擇和保存,工具

    harmony-utilsPickerUtil,拍照、文件選擇和保存,工具 harmony-utils 簡介與說明
    的頭像 發表于 06-27 16:03 ?91次閱讀

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

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

    harmony-utilsAssetUtil,關鍵資產存儲服務工具

    harmony-utilsAssetUtil,關鍵資產存儲服務工具
    的頭像 發表于 06-26 17:42 ?80次閱讀

    harmony-utilsArrayUtil,集合工具

    # harmony-utilsArrayUtil,集合工具 ## harmony-utils 簡介與說明 ------[
    的頭像 發表于 06-26 17:38 ?88次閱讀

    harmony-utilsAppUtil,APP相關工具

    harmony-utils一款功能豐富且極易上手的HarmonyOS工具庫,借助眾多實用工具,致力于助力開發者迅速構建鴻蒙應用。
    的頭像 發表于 06-26 09:24 ?98次閱讀
    <b class='flag-5'>harmony-utils</b><b class='flag-5'>之</b>AppUtil,APP<b class='flag-5'>相關</b><b class='flag-5'>工具</b><b class='flag-5'>類</b>
    主站蜘蛛池模板: 国产亚洲高清在线精品不卡 | 欧美色图 亚洲 | 男女视频免费观看 | 特一级黄色毛片 | 老师下面很湿很爽很紧 | 婷婷色在线观看 | 国产成人三级 | 最新仑乱免费视频 | 91大神精品长腿在线观看网站 | 一级特黄aa大片免费 | 老师喂我吃她的奶水脱她胸罩 | 福利体验区 | 在线色片 | 久久69| 我被黑人巨大开嫩苞在线观看 | 一级在线观看视频 | 天堂资源在线官网bt | 日韩草逼| 欧美性一级交视频 | 狠狠色丁香婷婷综合激情 | 一级片在线视频 | 亚洲欧美婷婷 | 色多多视频在线观看 | 欧美极品第一页 | 色网站综合| 深夜久久 | 午夜黄色网址 | 亚洲狠狠网站色噜噜 | 四虎伦理| 台湾黄色毛片 | 欧美一级艳片视频免费观看 | 天天射天天干天天 | 2o18国产大陆天天弄 | 好硬好湿好爽再深一点h视频 | 国模在线视频 | 起碰免费视频 | 手机看片福利盒子久久青 | 天天射天天干 | 欧美天堂视频 | 国内精品伊人久久大香线焦 | 久久福利青草精品资源 |