HarmonyOS 鸿蒙Next 组件页面沉浸式
HarmonyOS 鸿蒙Next 组件页面沉浸式
更多关于HarmonyOS 鸿蒙Next 组件页面沉浸式的实战教程也可以访问 https://www.itying.com/category-93-b0.html
[@Entry](/user/Entry)修饰的才是页面,单独[@Component](/user/Component)修饰的只是组件, 单独[@Component](/user/Component)的组件也能通过设置expandSafeArea属性来扩展其安全区域。
import { SafeAreaSub } from './saveSubPage'
@Entry
@Component
struct SafeAreaExample1 {
build() {
Row() {
SafeAreaSub()
}.height('100%')
}
}
// saveSubPage.ets
@Component
export struct SafeAreaSub {
@State text: string = ''
controller: TextInputController = new TextInputController()
build() {
Row() {
Column()
.height('100%').width('100%')
.backgroundImage($r('app.media.hello')).backgroundImageSize(ImageSize.Cover)
.expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM])
}.height('100%')
}
}
其他沉浸式效果: 1、调用setWindowSystemBarEnable接口,设置导航栏、状态栏不显示,从而达到沉浸式效果。 参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-V5#setwindowsystembarenable9
2、调用setWindowLayoutFullScreen接口,设置应用主窗口为全屏布局;然后调用setWindowSystemBarProperties接口,设置导航栏、状态栏的透明度、背景/文字颜色以及高亮图标等属性,使之保持与主窗口显示协调一致,从而达到沉浸式效果。
参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-V5#setwindowlayoutfullscreen9 https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-V5#setwindowsystembarproperties9
更多关于HarmonyOS 鸿蒙Next 组件页面沉浸式的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
针对HarmonyOS鸿蒙Next组件页面沉浸式效果的实现,以下是一些专业解答:
要实现组件页面的沉浸式效果,首先需要调整布局系统为全屏布局,使界面元素延伸到状态栏和导航条区域。这可以通过设置窗口全屏布局方案来实现,具体步骤包括在EntryAbility的onWindowStageCreate方法中调用setWindowLayoutFullScreen方法设置窗口全屏,并获取状态栏和导航条的高度,以便后续进行避让处理。
此外,还可以通过设置安全区域的expandSafeArea属性来达到沉浸式效果。这需要将整个页面的安全区范围延伸至非安全区,然后对滚动容器设置expandSafeArea属性,使滚动范围也延伸至非安全区。
在实现沉浸式效果时,需要注意UI元素的避让处理,避免可交互元素被状态栏或导航条遮挡。同时,还需要考虑沉浸式效果处理,如将状态栏和导航条颜色与界面元素颜色相匹配,以减少突兀感。
如果问题依旧没法解决请联系官网客服,官网地址是:https://www.itying.com/category-93-b0.html。