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

OpenHarmony 4.0 Release横屏配置

文章目录

  • 一、前言
  • 二、环境配置
  • 三、系统默认横屏
    • 3.1屏幕方向调试命令
    • 3.2配置不同值效果
    • 3.3 源码修改
    • 3.4 横屏异常处理
  • 四、应用设置屏幕方向
  • 五、总结

一、前言

OpenHarmony源码默认基于手机类竖屏设备配置,在某些行业或场景,如平板、电视、广告机等常常需要横屏显示,因此需要修改OpenHarmony 默认显示方向,由竖屏改为横屏。

二、环境配置

  • 系统版本: OpenHarmony 4.0 Release (4.0.10.13) 32bit
  • 设备平台:DAYU 200 RK3568

三、系统默认横屏

3.1屏幕方向调试命令

可使用hdc命令修改设备/system/etc/window/resources/display_manager_config.xml配置文件buildInDefaultOrientation参数,重启生效:

# 拷贝设备display_manager_config.xml 至本地桌面
hdc shell mount -o remount,rw /;hdc file recv /system/etc/window/resources/display_manager_config.xml  C:\Users\xxx\Desktop\display_manager_config.xml# 修改buildInDefaultOrientation并保存(默认为0)
<buildInDefaultOrientation>2</buildInDefaultOrientation># 拷贝本地display_manager_config.xml 至设备原路径
hdc shell mount -o remount,rw /;hdc file send C:\Users\xxx\Desktop\display_manager_config.xml /system/etc/window/resources/display_manager_config.xml#重启生效
hdc shell reboot

3.2配置不同值效果

  • 未指定: <buildInDefaultOrientation>0<buildInDefaultOrientation> 表示未指定屏幕方向,使用默认方向,与<buildInDefaultOrientation>1<buildInDefaultOrientation>显示一致
  • 竖屏: <buildInDefaultOrientation>1<buildInDefaultOrientation>
  • 横屏: <buildInDefaultOrientation>2<buildInDefaultOrientation>
  • 竖屏反转: <buildInDefaultOrientation>3<buildInDefaultOrientation>
  • 横屏反转: <buildInDefaultOrientation>4<buildInDefaultOrientation>

3.3 源码修改

rk3568设备/system/etc/window/resources/display_manager_config.xml配置文件在源码中对应
foundation/window/window_manager/resources/config/rk3568/display_manager_config.xml

    <!-- Indicates orientation of the built-in screen --><!-- 0: Orientation::UNSPECIFIED --><!-- 1: Orientation::VERTICAL         2: Orientation::HORIZONTAL--><!-- 3: Orientation::REVERSE_VERTICAL 4: Orientation::REVERSE_HORIZONTAL --><buildInDefaultOrientation>2</buildInDefaultOrientation>

全编后更新系统验证。

细心的你可能发现,Launcher概率性竖屏,并显示异常,但系统设置应用横屏正常。

3.4 横屏异常处理

系统由横屏改为竖屏后,仍有一些未完全适配的问题,如:开机Logo&开机视频仍竖屏、Launcher概率性竖屏异常,输入法UI横屏适配异常、OTA升级UI竖屏显示等。

  • 开机画未横屏显示:使用横屏开机画替换原本的竖屏开机画
    原 开机第一画:device\board\hihope\rk3568\kernel\logo.bmp

    原 开机第二画:device\board\hihope\rk3568\kernel\logo_kernel.bmp
  • 开机动画和Launcher概率性横屏显示竖屏:已有先关文章,此处笔者不再赘述,可参考:OpenHarmony系统解决方案 - 配置屏幕方向导致开机动画和Launcher显示异常

✍OneMoreThink
修改foundation/window/window_manager/wmserver/src/window_node_container.cpp可模块化编译和验证:
注意:64位系统, libwms.z.so拷贝至/system/lib64/libwms.z.so

#模块化编译libwms.z.so
./build.sh -p rk3568 --build-target libwms#将生成的libwms.z.so替换设备libwms.z.so
hdc shell mount -o remount,rw /;hdc file send xxx\out\rk3568\window\window_manager\libwms.z.so /system/lib/libwms.z.so
# 重启设备生效
hdc shell reboot

更多OpenHarmony模块编译技巧可参考OpenHarmony模块化编译↩

  • recovery升级界面未横屏显示: 将在后续文章中分享,请关注更新~

四、应用设置屏幕方向

本章节介绍在应用中如何设置屏幕方向

  • 设置应用UI方向
    可在module.json5 abilities配置中添加orientation:
"abilities": [{"name": "EntryAbility","srcEntry": "./ets/entryability/EntryAbility.ets",..."orientation": "auto_rotation","startWindowIcon": "$media:startIcon","startWindowBackground": "$color:start_window_background",...}]

参考:module.json5配置文件-abilities标签↩
orientation 标识当前UIAbility组件启动时的方向,支持配置枚举,或启动方向资源索引。
启动方向枚举支持的取值如下:

- unspecified:未指定方向,由系统自动判断显示方向。
- landscape:横屏。
- portrait:竖屏。
- follow_recent:跟随背景窗口的旋转模式。
- landscape_inverted:反向横屏。
- portrait_inverted:反向竖屏。
- auto_rotation:随传感器旋转。
- auto_rotation_landscape:传感器横屏旋转,包括横屏和反向横屏。
- auto_rotation_portrait:传感器竖屏旋转,包括竖屏和反向竖屏。
- auto_rotation_restricted:传感器开关打开,方向可随传感器旋转。
- auto_rotation_landscape_restricted:传感器开关打开,方向可随传感器旋转为横屏, 包括横屏和反向横屏。
- auto_rotation_portrait_restricted:传感器开关打开,方向随可传感器旋转为竖屏, 包括竖屏和反向竖屏。
- locked:传感器开关关闭,方向锁定。
- auto_rotation_unspecified:受开关控制和由系统判定的自动旋转模式。
- follow_desktop:跟随桌面的旋转模式。配置启动方向的资源索引时,取值为长度不超过255字节的字符串,配置示例:$string:orientation。说明:- 从API version 14开始,支持配置启动方向资源索引。	字符串	该标签可缺省,缺省值为unspecified。
  • 设置系统屏幕方向
    使用@ohos.screen setOrientation()接口即可
    let promise: Promise<Array<screen.Screen>> = screen.getAllScreens();promise.then((data: Array<screen.Screen>) => {this.mScreen = data[0];this.mScreenRotation = this.mScreen.orientationconsole.log('Succeeded in getting all screens. Data:' + JSON.stringify(data));}).catch((err: BusinessError) => {console.log('Failed to get all screens. Cause: ' + JSON.stringify(err));});this.mScreen.setOrientation(this.mScreenRotation, (err: BusinessError) => {const errCode: number = err.code;if (errCode) {console.error('Failed to set the vertical orientation. Code: ' + JSON.stringify(err));return;}console.info('Succeeded in setting the vertical orientation.');});
    

请添加图片描述
Demo参考:ScreenDemo

五、总结

Congratulations~✌ 通过本文,你已基本掌握:

  • OpenHarmony系统默认屏幕方向配置
  • OpenHarmony横屏Logo、bootanimation和Launcher显示异常处理
  • OpenHarmony 应用如何配置屏幕方向和设置系统屏幕方向

接下来尝试更多有趣OpenHarmony源码开发创作吧~

了解更多关于OpenHarmony文章↩

http://www.dtcms.com/a/399509.html

相关文章:

  • 网站开发前端与后端铁汉生态建设有限公司网站
  • 服务器安全基线配置
  • 随机森林算法详解:从原理到实战
  • 数据库回表查询解析:从原理到实战优化
  • 详解单元测试、集成测试、系统测试
  • 企业网站设计要点郑州seo哪家公司最强
  • 互动网站制作wordpress add option
  • wordpress 上传 重命名郑州seo外包平台
  • 【C++实战㊱】解锁C++依赖倒置:从理论到实战的蜕变之旅
  • 项目案例作业2:对案例进行面向对象分析
  • 锤子助手插件功能七十二:对话内图片「一键添加至表情」
  • 饮食网站开发需求网站开发 面试
  • Deepseek本地部署教程模型怎么选择?按需选择让效率翻倍
  • 企业备案网站服务内容wordpress ajax搜索
  • 自己做网站不推广备案可以不关闭网站吗
  • 12_OkHttp初体验
  • 硅基计划5.0 MySQL 壹 初识MySQL
  • 网站规划建设方案免费微信点餐小程序
  • Ford-Fulkerson最大流算法数学原理详解
  • 湛江做寄生虫网站wordpress修改端口
  • 从技术角度分析 “诺亚参数” 生成式设计工具
  • 做pc端网站代理商广告传媒网站模板
  • All In AI之三:一文构建Python核心语法体系
  • 湖州公司做网站南山龙岗最新通告
  • 南通建设招聘信息网站石家庄网站建设服务
  • 网站配资公司网站网站推荐免费的
  • asp旅游网站模板下载阜新本地网站建设平台
  • DBA 系统学习计划(从入门到进阶)
  • 列出网站目录wordpress正文底部版权声明
  • 网站改版建设 有哪些内容什么叫关键词