IT评测·应用市场-qidao123.com

标题: HarmonyOS 鸿蒙手机APP开发 全屏陶醉式封装 [打印本页]

作者: 用户国营    时间: 2025-1-25 03:40
标题: HarmonyOS 鸿蒙手机APP开发 全屏陶醉式封装
//全屏陶醉式
// 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企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 IT评测·应用市场-qidao123.com (https://dis.qidao123.com/) Powered by Discuz! X3.4