HarmonyOS 自定义弹框导致机测不通过

因为系统提供的AlertDialog在暗黑模式下无法设置标题和消息的字体颜色所以使用subwindow实现了alert的功能(如图)但是在机测的时候报错,提示“无法回退”,导致应用上架失败可是alert弹框本来就不能回退的,这个怎么处理呢?

HarmonyOS 自定义弹框导致机测不通过-鸿蒙开发者社区

HarmonyOS
2024-11-18 11:42:46
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
shlp

自定义一个组件作为弹框可以设置标题和消息的字体颜色。

import promptAction from '@ohos.promptAction' 
let customDialogId: number = 0 
@Builder 
function customDialogBuilder() { 
  Column() { 
    Text('title ').fontSize(10).fontColor(Color.Red) 
    Text('message ').fontSize(10).fontColor(Color.Blue) 
    Row() { 
      Button("确认").onClick(() => { 
        promptAction.closeCustomDialog(customDialogId) 
      }) 
      Blank().width(50) 
      Button("取消").onClick(() => { 
        promptAction.closeCustomDialog(customDialogId) 
      }) 
    } 
  }.height(100) 
} 
 
@Entry 
@Component 
struct Page17 { 
  @State message: string = 'Hello World' 
 
  build() { 
    Row() { 
      Column() { 
        Text(this.message) 
          .fontSize(50) 
          .fontWeight(FontWeight.Bold) 
          .onClick(() => { 
            promptAction.openCustomDialog({ 
              builder: customDialogBuilder.bind(this) 
            }).then((dialogId: number) => { 
              customDialogId = dialogId 
            }) 
          }) 
      } 
      .width('100%') 
    } 
    .height('100%') 
  } 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.

可以重用 定义customDialogBuilder的页面导出 使用的页面导入。

import {customDialogBuilder} from './Page17'
  • 1.
分享
微博
QQ
微信
回复
2024-11-18 17:26:43
相关问题
HarmonyOS 自定义封装问题
782浏览 • 1回复 待解决
HarmonyOS 自定义组件问题
1244浏览 • 1回复 待解决
HarmonyOS 自定义不能全屏
888浏览 • 1回复 待解决
自定义的状态获取
1566浏览 • 1回复 待解决
ohpm dayjs编译不通过
885浏览 • 1回复 待解决
是否可以自定义权限文字
2515浏览 • 1回复 待解决
HarmonyOS app版本升级需要自定义
884浏览 • 1回复 待解决
HarmonyOS 如何设置自定义的颜色
676浏览 • 1回复 待解决
HarmonyOS 自定义遮罩透传问题
703浏览 • 1回复 待解决
HarmonyOS 项目验签不通过
669浏览 • 1回复 待解决
如何给自定义加上圆角背景
2820浏览 • 1回复 待解决
自定义如何在UIAbility中弹出?
224浏览 • 0回复 待解决
自定义,遮罩背景颜色无法设置
991浏览 • 1回复 待解决
HarmonyOS 自定义关闭后页面上移
709浏览 • 1回复 待解决
HarmonyOS 背景色如何自定义图片
631浏览 • 1回复 待解决