HarmonyOS鸿蒙Next中2in1(PC)下面如何让应用全屏?

HarmonyOS鸿蒙Next中2in1(PC)下面如何让应用全屏?

setWindowSystemBarEnable9+

setWindowSystemBarEnable(names: Array<'status' | 'navigation'>): Promise<void>

设置主窗口状态栏、底部导航(根据用户设置,可表现为导航条或三键导航栏)的可见模式,状态栏和底部导航通过status控制、navigation参数无效果,使用Promise异步回调。

从API version 12开始,该接口在2in1设备上调用不生效,其他设备在分屏模式(即窗口模式为window.WindowStatusType.SPLIT_SCREEN)、自由悬浮窗口模式(即窗口模式为window.WindowStatusType.FLOATING)、自由多窗模式(可点击设备控制中心中的自由多窗按钮开启)下调用不会立刻生效,只有进入全屏主窗口才会生效。

调用生效后返回并不表示状态栏和底部导航区域的显示或隐藏已完成。子窗口调用后不生效。非全屏模式(悬浮窗、分屏等场景)下配置不生效。

setWindowLayoutFullScreen9+

setWindowLayoutFullScreen(isLayoutFullScreen: boolean): Promise<void>

设置主窗口或子窗口的布局是否为沉浸式布局,使用Promise异步回调。从API version 14开始,该接口在2in1设备或平板设备的自由多窗模式(可点击设备控制中心中的自由多窗按钮开启)下调用不生效。

沉浸式布局生效时,布局不避让状态栏与底部导航区域,组件可能产生与其重叠的情况。

非沉浸式布局生效时,布局避让状态栏与底部导航区域,组件不会与其重叠。

现在使用得API17 应该如何才能让我得应用全屏,隐藏状态栏导航栏.


更多关于HarmonyOS鸿蒙Next中2in1(PC)下面如何让应用全屏?的实战教程也可以访问 https://www.itying.com/category-93-b0.html

4 回复

好了,

win.maximize(window.MaximizePresentation.ENTER_IMMERSIVE)
win.setTitleAndDockHoverShown(true,false)

使用这两个就可以了

更多关于HarmonyOS鸿蒙Next中2in1(PC)下面如何让应用全屏?的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


学习了,

在HarmonyOS Next的2in1 PC设备上,可通过以下方式实现应用全屏:

  1. 在Ability的config.json中配置"window":“fullScreenEnabled”:true
  2. 运行时调用Window类setFullScreen方法
  3. 确保UI布局使用百分比或资源限定符适配不同屏幕
  4. 针对折叠屏特性,在uiAbility中监听display事件处理屏幕变化

全屏显示需要应用适配FlexibleLayout布局能力。注意避开刘海屏区域需使用safeArea规避。

在HarmonyOS Next API 17中,对于2in1(PC)设备实现应用全屏的正确做法是:

  1. 首先确保窗口进入全屏模式:
import window from '@ohos.window';

let windowClass = await window.getLastWindow(this.context);
await windowClass.setWindowLayoutFullScreen(true);
  1. 对于状态栏和导航栏的隐藏,由于API 12+在2in1设备上setWindowSystemBarEnable已不生效,推荐改用以下方案:
await windowClass.setWindowSystemBarProperties({
  statusBarColor: '#00000000', // 透明色
  navigationBarColor: '#00000000', // 透明色
  isStatusBarLightIcon: true,
  isNavigationBarLightIcon: true
});
  1. 注意:
  • 该方法需要窗口已处于全屏状态才会生效
  • 在自由多窗模式下无法强制全屏
  • 建议在onWindowStageCreate生命周期中调用
  • 沉浸式布局下需自行处理内容与系统栏的重叠问题

完整示例:

async function enterFullScreen() {
  try {
    let windowClass = await window.getLastWindow(this.context);
    await windowClass.setWindowLayoutFullScreen(true);
    await windowClass.setWindowSystemBarProperties({
      statusBarColor: '#00000000',
      navigationBarColor: '#00000000',
      isStatusBarLightIcon: true,
      isNavigationBarLightIcon: true
    });
  } catch (err) {
    console.error(`Failed to enter fullscreen: ${err}`);
  }
}
回到顶部