HarmonyOS 鸿蒙手机APP开发 全屏陶醉式封装

打印 上一主题 下一主题

主题 862|帖子 862|积分 2586

//全屏陶醉式
// window 鸿蒙提供好的一个全局对象
import { Logger } from './Logger'
import window from '@ohos.window'
// Logger.info('window', JSON.stringify(window))
export class WindowManager {
  static async fullScreen() {
    // 全屏 setWindowLayoutFullScreen    是页面窗口的一个方法
    // 页面窗口怎么获取 => window.getLastWindow()
    const xx = await window.getLastWindow(getContext()) // Index页面窗口
    xx.setWindowLayoutFullScreen(true) // 全屏
    // 使用xx继续获取安全区的高度
    const res = xx.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM) // 获取安全区
    const height = px2vp(res.topRect.height) // 安全区的上边的高度  默认是px单位   临时地换算成vp
    // 使用appStorage存储高度
    AppStorage.setOrCreate('height', height)
    // 复杂 但不消你写 => 这里许多的功能都是调用鸿蒙底层提供的一个函数完成
  }
  static async exitFullScreen() {
    // 退出全屏
    const xx = await window.getLastWindow(getContext()) // Index页面窗口
    xx.setWindowLayoutFullScreen(false)
  }
  static async setColor(color: string) {
    // 设置状态栏的文字颜色  黑色   白色
    const xx = await window.getLastWindow(getContext()) // Index页面窗口
    // 设置状态栏文字颜色
    xx.setWindowSystemBarProperties({
      statusBarContentColor: color // 必须是十六进制的颜色 必须写全
    })
  }
}
  静态方法调用  哪个页面需要做全屏陶醉式 就调用

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

用户国营

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表