当前位置:   article > 正文

harmonyOS开发技巧(二)——沉浸式以及状态栏高_getwindowavoidarea

getwindowavoidarea

1. 设置沉浸式:win.setWindowLayoutFullScreen(true);

2. 获取状态栏的高:win.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM)以及win.on('avoidAreaChange', (data) => {})。

  1. import UIAbility from '@ohos.app.ability.UIAbility';
  2. import window from '@ohos.window';
  3. import { logger } from '@ohos/commonLib';
  4. const TAG: string = 'EntryAbility';
  5. export default class EntryAbility extends UIAbility {
  6. onCreate(want, launchParam) {
  7. logger.info(TAG, 'onCreate');
  8. }
  9. onDestroy() {
  10. logger.info(TAG, 'onDestroy');
  11. }
  12. onWindowStageCreate(windowStage: window.WindowStage) {
  13. windowStage.loadContent('pages/StartPage', (err, data) => {
  14. if (err.code) {
  15. logger.info(TAG, 'loadContent err=', JSON.stringify(err) ?? '');
  16. return;
  17. }
  18. logger.info(TAG, 'loadContent success=', JSON.stringify(data) ?? '');
  19. });
  20. }
  21. private setWindow(windowStage: window.WindowStage) {
  22. windowStage.getMainWindow().then((win: window.Window) => {
  23. win.setWindowLayoutFullScreen(true);
  24. try {
  25. const avoidArea = win.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM);
  26. if (avoidArea) {
  27. // AppStorage.SetOrCreate('statusBarHeight', avoidArea?.topRect?.height);
  28. }
  29. win.on('avoidAreaChange', (data) => {
  30. // AppStorage.SetOrCreate('statusBarHeight', data?.area?.topRect?.height);
  31. });
  32. } catch (err) {
  33. }
  34. })
  35. }
  36. }

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号