HarmonyOS 系统返回功能怎么让上一个页面的状态栏清除状态?

现在就是一个页面,状态栏是全屏的,没有设置statusToHeight, push到新页面, 新页面有自己的状态栏,设置了statusToHeight,新页面操作完成返回到上一个页面,但是依然保留了状态栏的高度和状态,而且生命周期也没走

阅读 534
1 个回答

将生命周期换成onPageShow,参考demo如下:

第一个页面

import { router } from '@kit.ArkUI'
import { window } from '@kit.ArkUI';
import { common } from '@kit.AbilityKit';

@Entry
@Component
struct Index {
  onPageShow(): void {
    try {
      let context = getContext(this) as common.UIAbilityContext;
      window.getLastWindow(context).then((lastWindow) => {
        lastWindow.setWindowLayoutFullScreen(true)
      });
    } catch (exception) {
      console.error(fail: ${JSON.stringify(exception)});
    }
  }
  onPageHide(): void {
    try {
      let context = getContext(this) as common.UIAbilityContext;
      window.getLastWindow(context).then((lastWindow) => {
        lastWindow.setWindowLayoutFullScreen(false)
      });
    } catch (exception) {
      console.error(fail: ${JSON.stringify(exception)});
    }
  }
  build() {
    Column() {
      Text('第一个页面')
        .width('100%')
        .height(50)
        .backgroundColor(Color.Red)
      Text('Push')
        .textAlign(TextAlign.Center)
        .width(80)
        .height(60)
        .fontColor(Color.White)
        .backgroundColor(Color.Blue)
        .onClick(() => {
          router.pushUrl({
            url: 'pages/TestPage',
          })
        })
    }
    .backgroundColor(Color.Gray)
    .width('100%')
    .height('100%')
  }
}

第二个页面

import { router } from '@kit.ArkUI'

@Entry
@Component
struct TestPage {
  build() {
    Column() {
      Image($r('sys.media.ohos_ic_back'))
        .width(50)
        .height(40)
        .onClick(()=>{
          router.back()
        })
      Text('第二个页面')
        .width('100%')
        .height(50)
        .backgroundColor(Color.Red)
    }
    .width('100%')
    .height('100%')
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进