API9和API10实现沉浸式窗口的方式

API9和API10实现沉浸式窗口的方式

HarmonyOS
2024-01-30 19:00:16
3179浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
youpeng99
  • 在API9中,setFullScreen被废弃,建议联合使用setWindowLayoutFullScreen和setWindowSystemBarEnable。
onWindowStageCreate(windowStage: window.WindowStage) { 
  // API9 全屏判断 
  let isLayoutFullScreen = true; 
  let windowClass = null; 
  // Main window is created, set main page for this ability 
  hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); 
 
  windowStage.loadContent('pages/Index', (err, data) => { 
    if(err.code){ 
      hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); 
      return; 
    } 
    windowClass = data; 
    hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); 
  }); 
 
  // API9设置窗口全屏化 
  try { 
    windowClass.setWindowLayoutFullScreen(isLayoutFullScreen, (err) => { 
      if(err.code){ 
        console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err)); 
        return; 
      } 
      console.info('Succeeded in setting the window layout to full-screen mode.'); 
    }); 
  } catch (exception) { 
    console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(exception)); 
  } 
 
  // API9不显示导航栏、状态栏 
  // 如果需要沉浸式,将 names = []; 
  let names = []; 
  try { 
    windowClass.setWindowSystemBarEnable(names, (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.'); 
    }); 
  } catch (exception) { 
    console.error('Failed to set the system bar to be invisible. Cause:' + JSON.stringify(exception)); 
  } 
}
  • 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.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 在API10中,使用新的UI组件expandSafeArea也可以完成沉浸式窗口的设置。
@Entry 
@Component 
struct Index { 
  @State message: string = '内容栏全屏测试' 
 
  build() { 
    Row() { 
      Column() { 
        Text(this.message) 
          .fontSize(20) 
          .fontWeight(FontWeight.Bold) 
      } 
      .width('100%') 
      .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.BOTTOM, SafeAreaEdge.TOP]) 
    } 
    .height('100%') 
    .backgroundColor(Color.Orange) 
  } 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.

参考链接

安全区域

分享
微博
QQ
微信
回复
2024-01-31 23:22:03


相关问题
HarmonyOS api10如何给子窗口设置圆角
1168浏览 • 1回复 待解决
deveco studio中如何升级API10
3930浏览 • 1回复 已解决
HarmonyOS 关于窗口沉浸设置方式
850浏览 • 1回复 待解决
HarmonyOS API9工程升级迁移策略
1028浏览 • 1回复 待解决
DevEco Studio 3.0.0.900 找不到API9
6890浏览 • 1回复 待解决
Arkts开发 api9 中怎么实现扫码功能?
4080浏览 • 1回复 待解决
API11编译har包可以在api10上使用吗
2733浏览 • 1回复 待解决
Api9 Stage问题有知道吗?
1474浏览 • 1回复 待解决
Api 9 Stage 模型分布如何实现
3618浏览 • 1回复 待解决
harmonyOS基于api9如何调用相机拍照?
5152浏览 • 1回复 待解决
harmonyOS API9用不了相机吗
4972浏览 • 1回复 待解决
api9应用底配手机是否能用?
3084浏览 • 1回复 待解决
API9下用ets开发APP如何退出 ?
3895浏览 • 1回复 待解决
API9只能用真机调试吗?
1631浏览 • 1回复 待解决
Harmony API9之后 GIS 解决方案有哪些?
3025浏览 • 1回复 待解决