HarmonyOS 悬浮窗在横屏下如何强制显示竖屏

应用会创建一个悬浮窗,想让悬浮窗在横屏状态下也是竖屏显示,按如下方式配置了悬浮窗强制竖屏,但是不生效

HarmonyOS 悬浮窗在横屏下如何强制显示竖屏-鸿蒙开发者社区

HarmonyOS
2024-12-18 15:32:59
7779浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
FengTianYa

可以通过设置windowClass.setPreferredOrientation(window.Orientation.LOCKED),LOCKED会根据当前显示的方向锁定屏幕禁止旋转

import { window } from '@kit.ArkUI';

@Entry
@Component
struct Test {
  @State message: string = 'Hello World';

  build() {
    Column() {
      Text(this.message)
        .id('Index4HelloWorld')
        .fontSize(50)
        .fontWeight(FontWeight.Bold)
        .fontColor(Color.Black)
        .alignRules({
          center: { anchor: '__container__', align: VerticalAlign.Center },
          middle: { anchor: '__container__', align: HorizontalAlign.Center }
        })
      Button('锁定').onClick(() => {
        window.getLastWindow(getContext(this), (err, win) => {
          win.setPreferredOrientation(window.Orientation.LOCKED)
        })
      })
        .fontColor(Color.Black)

      Button('解除锁定')
        .fontColor(Color.Black)
        .onClick(() => {
          window.getLastWindow(getContext(this), (err, win) => {
            win.setPreferredOrientation(window.Orientation.AUTO_ROTATION)
          })
        })
    }
    .height('100%')
    .width('100%')
    .backgroundColor(Color.Orange)
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
分享
微博
QQ
微信
回复
2024-12-18 18:38:19
相关问题
应用如何适配华为悬浮?
3493浏览 • 1回复 待解决
如何获取当前是还是啊?
5836浏览 • 1回复 待解决
HarmonyOS 查询当前状态是还是
1157浏览 • 1回复 待解决
openharmony jsFA 如何显示
8130浏览 • 1回复 待解决
page页面如何设置为显示
2432浏览 • 1回复 待解决
HarmonyOS 多模块悬浮显示不出来
1131浏览 • 1回复 待解决
HarmonyOS video如何播放?
1078浏览 • 1回复 待解决