import { promptAction } from '@kit.ArkUI';
@Entry
@Component
struct Index {
aboutToAppear(): void {
promptAction.showToast({ message: "切换为夜间模式" })
getContext(this).getApplicationContext().setColorMode(0)
}
build() {
Column() {
Text("Hello, World!")
}
.width('100%')
.height('100%')
}
}
启动后,toast 会从上面飞到下面,而不是直接出现 ,如果把 getContext(this).getApplicationContext().setColorMode(0) 这一行去掉,则没有这个问题。
解决方案:
按照如下方式修改即可:
相关api参考链接:https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-arkui/js-apis-promptAction.md\#toastshowmode11