Skip to content

即时反馈

分成两种

  • DEFAULT

  • TOP_MOST

区别

简单来说一句话:

当页面有表单的时候需要使用软键盘

  • DEFAULT: 以 UIExtension 为主窗中布局,对齐方式与 UIExtension 对齐
  • TOP_MOST: 以宿主窗口为主窗中布局,对齐方式与宿主窗口对齐。

一般 default 就可以了

代码

ts
import { promptAction } from '@kit.ArkUI';

@Entry
@Component
struct Index {
    build() {
        Column({ space: 10 }) {
            TextInput()
            Button() {
                Text("DEFAULT类型Toast")
                    .fontSize(20)
                    .fontWeight(FontWeight.Bold)

            }
            .width('100%')
            .onClick(() => {
                promptAction.showToast({
                    message: "ok,我是DEFAULT toast",
                    duration: 3000,
                    bottom: 30,
                    backgroundColor: '#FF2100',
                    textColor: "#080623",
                    backgroundBlurStyle: BlurStyle.NONE, // 不加这个属性 文字颜色和背景色出不来
                    shadow: ({
                        radius: 10,
                        color: Color.Grey,
                        offsetX: 10,
                        offsetY: 10
                    }),
                        })
            })

            Button() {
                Text("TOPMOST类型Toast")
                    .fontSize(20)
                    .fontWeight(FontWeight.Bold)
            }
            .width('100%')
            .onClick(() => {
                promptAction.showToast({
                    message: "ok,我是TOP_MOST toast",
                    showMode: promptAction.ToastShowMode.TOP_MOST,
                    duration: 3000,
                    bottom: 30,
                    backgroundColor: '#FF2100',
                    textColor: "#080623",
                    backgroundBlurStyle: BlurStyle.NONE, // 不加这个属性 文字颜色和背景色出不来
                    shadow: ({
                        radius: 10,
                        color: Color.Grey,
                        offsetX: 10,
                        offsetY: 10
                    }),
                        })
            })
        }.height('100%')
    }
}