全屏设置使用到了setWindowSystemBarEnable和setWindowLayoutFullScreen

使用setWindowLayoutFullScreen

onWindowStageCreate(windowStage: window.WindowStage) {
  // Main window is created, set main page for this ability
  hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
let isLayoutFullScreen = true;
try {
  let promise = windowClass.setWindowLayoutFullScreen(isLayoutFullScreen);
  promise.then(()=> {
    console.info('Succeeded in setting the window layout to full-screen mode.');
  }).catch((err)=>{
    console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err));
  });
} catch (exception) {
  console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(exception));
}

类型为boolean

该全屏状态下状态栏、导航栏仍然显示。

使用setWindowSystemBarEnable异步函数

onWindowStageCreate(windowStage: window.WindowStage) {
  // Main window is created, set main page for this ability
  hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
  let windowClass = null;
  windowStage.getMainWindow((err, data) => {
    if (err.code) {
      console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err));
      return;
    }
    windowClass = data;
    console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
    windowClass.setWindowSystemBarEnable([], (err) => {
      if (err.code) {
        console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(err));
        return;
      }
      console.info('Succeeded in setting the system bar to be invisible.');
    });

callback和Promise为返回值,<Window>为返回类型,异步函数获取窗口时通过返回值类型找同类型获取。

使用setWindowSystemBarEnable同步函数

async onWindowStageCreate(windowStage: window.WindowStage) {
  // Main window is created, set main page for this ability
  hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
  //配置窗口,添加回调
  let windowClass = await windowStage.getMainWindow()
​
    //设置全屏
​
    windowClass.setWindowSystemBarEnable([], (err) => {
      if (err.code) {
        console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(err));
        return;
      }
      console.info('Succeeded in setting the system bar to be invisible.');
    });

设置为全屏时names=[]不为全屏时names=[‘status’, ‘navigation’];

Logo

社区规范:仅讨论OpenHarmony相关问题。

更多推荐