当前位置: 首页 > article >正文

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

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

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

import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
import { logger } from '@ohos/commonLib';

const TAG: string = 'EntryAbility';

export default class EntryAbility extends UIAbility {
  onCreate(want, launchParam) {
    logger.info(TAG, 'onCreate');
  }

  onDestroy() {
    logger.info(TAG, 'onDestroy');
  }

  onWindowStageCreate(windowStage: window.WindowStage) {
    windowStage.loadContent('pages/StartPage', (err, data) => {
      if (err.code) {
        logger.info(TAG, 'loadContent err=', JSON.stringify(err) ?? '');
        return;
      }
      logger.info(TAG, 'loadContent success=', JSON.stringify(data) ?? '');
    });
  }

  private setWindow(windowStage: window.WindowStage) {
    windowStage.getMainWindow().then((win: window.Window) => {
      win.setWindowLayoutFullScreen(true);
      try {
        const avoidArea = win.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM);
        if (avoidArea) {
          // AppStorage.SetOrCreate('statusBarHeight', avoidArea?.topRect?.height);
        }
        win.on('avoidAreaChange', (data) => {
          // AppStorage.SetOrCreate('statusBarHeight', data?.area?.topRect?.height);
        });
      } catch (err) {

      }
    })
  }
}


http://www.kler.cn/news/162956.html

相关文章:

  • 前端知识笔记(三十七)———Django与Ajax
  • 2023年12月8日:UI登陆界面
  • 用C语言实现队列的顺序结构
  • 4.PyTorch——优化器
  • Bert-vits2新版本V2.1英文模型本地训练以及中英文混合推理(mix)
  • 【c语言指针详解】指针的基本概念和用法
  • 面对对象基础案例
  • React中使用react-json-view展示JSON数据
  • 2023年甘肃职业院校技能大赛(中职教师组)网络安全竞赛样题(五)
  • 持续集成交付CICD:CentOS 7 安装 Nexus 3.63
  • Flask template+Vue +项目中include引入其他模版(其他模版也会用到vue)的使用探索
  • 独立服务器的主要应用方向有什么_Maizyun
  • 云原生(Cloud Native)——概念,技术,背景,优缺点,实践例子
  • Vue3如何优雅的跨组件通信
  • C++_对C数据类型的扩展
  • 整数以及浮点数在内存中的存储
  • 等待和通知
  • 联想电脑重装系统Win10步骤和详细教程
  • Ubuntu22.04 交叉编译fdk-aac for Rv1106
  • 【软件安装】VMware安装Centos7虚拟机并且设置静态IP,实现Windows和Centos7网络互相访问
  • Tair(2):Tair安装部署
  • 检测判断IP合法性API接口
  • Ubuntu 修改当前用户的名称
  • 膳食补充剂行业分析:2028年中国市场有望突破3700亿元
  • 有限空间作业中毒窒息事故频发,汉威科技创新方案护航
  • Flink 使用场景
  • K8S集群优化的可执行优化
  • 带大家做一个,易上手的家常辣子鸡
  • HbuilderX使用Uniapp+Vue3安装uview-plus
  • redis-学习笔记(list)