简介
本项目介绍了设置窗口全屏和扩展组件安全区域两种实现沉浸式效果的方式,并对状态栏、导航栏、挖空区域根据不同场景进行适配,为用户提供更优的视觉体验。
部分页面展示


首页
商城页
游戏页
部分代码展示
- import{ Shopping, ProductDetail, FaqList, ShoppingFullScreen }from'shopping';
- import{ Route, ROUTES }from'../constants/Constants';
- import{ VideoPlayer }from'./VideoPlayer';
- import{ MiniGame }from'./MiniGame';
- import{ MusicPlayer }from'./MusicPlayer';
- @Entry
- @Component
- struct Index
- @ProvidenavPageInfos: NavPathStack =newNavPathStack();
- go(to:string|undefined) {
- if(!to) {
- return;
- }
- this.navPageInfos.pushPath({name: to });
- }
- @Builder
- NavPageMap(name:string) {
- if(name ==='Shopping') {
- Shopping();
- }elseif(name ==='ProductDetail') {
- ProductDetail();
- }elseif(name ==='FaqList') {
- FaqList();
- }elseif(name ==='VideoPlayer') {
- VideoPlayer();
- }elseif(name ==='MiniGame') {
- MiniGame();
- }elseif(name ==='MusicPlayer') {
- MusicPlayer();
- }elseif(name ==='ShoppingFullScreen') {
- ShoppingFullScreen()
- }
- }
- build() {
- Navigation(this.navPageInfos) {
- Column() {
- Text($r('app.string.title'))
- fontWeight(FontWeight.Bold)
- fontSize(30)
- fontColor('#E6000000')
- width('100%')
- height(140)
- ForEach(ROUTES, (route: Route) =>
- Text(route.title)
- width('100%')
- fontColor('#99000000')
- fontSize(18)
- Column() {
- ForEach(route.children || [], (routeItem: Route, index) =>
- if(index !==0) {
- Divider()
- color('#0D000000')
- strokeWidth(0.5)
- }
- Row() {
- Text(routeItem.title)
- fontWeight(FontWeight.Medium)
- Blank()
- Image($r('app.media.arrow_right'))
- width(24)
- height(24)
- }
- width('100%')
- padding({top:12,bottom:12})
- onClick(() => this.go(routeItem.to))
- (routerItem: Route) => JSON.stringify(routerItem))
- }
- width('100%')
- backgroundColor(Color.White)
- borderRadius(20)
- margin({top:16,bottom:28})
- padding({left:12,right:12})
- (route: Route) => JSON.stringify(route))
- }
- width('100%')
- height('100%')
- backgroundColor('#F1F3F5')
- padding(16)
- }
- hideToolBar(true)
- hideTitleBar(true)
- mode(NavigationMode.Stack)
- navDestination(this.NavPageMap)
- }
- }
使用说明:
- 首页列出了沉浸式页面的实现方式和常见场景,点击对应的菜单项进入即可。
- 商城首页中点击某个商品进入商品详情页,点击详情页中常见问题区域进入商品常见问题页面,下滑到观察列表底部的避让情况。
- 避让挖孔的小游戏页面可通过切换不同挖孔位置的机型观察避让挖孔功能。
工程目录

项目相关描述
具体实现
- 使用setWindowLayoutFullScreen()方法设置窗口全屏或设置expandSafeArea属性扩展组件安全区域实现沉浸式效果。
- 常见沉浸式效果中的具体适配详见代码。
相关权限
不涉及。
依赖
不涉及
约束与限制
1.本示例仅支持标准系统上运行,支持设备:华为手机。
2.HarmonyOS系统:HarmonyOS 5.0.0 Release及以上。
3.DevEco Studio版本:DevEco Studio 5.0.0 Release及以上。
4.HarmonyOS SDK版本:HarmonyOS 5.0.0 Release SDK及以上。
总结
本项目实现了一些简单的功能,但可以再对其进行完善,从而使其功能种类更加丰富。