HarmonyOS CustomDialog中backgroundColor无法设置透明颜色

CustomDialog希望通过backgroundColor设置透明展示特殊弹框样式,结果无效

普通模式下是灰色,深色模式下是黑色,无法达到想要的效果

HarmonyOS
2024-12-26 13:56:33
950浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
aquaa

目前CustomDialog设置透明就是backgroundColor: 'rgba(0,0,0,0)',如果不能满足要求,可以尝试使用navigation的方式 ,NavDestination支持Dialog类型页面: NavDestinationMode.DIALOG: 默认透明,具体可参考下面demo,看能否满足需求:

【Page6253.ets】

@Component
struct Page6253 {

  @Consume('pageInfos') pageInfos: NavPathStack;

  build() {
    NavDestination() {
      Button('push Page01')
        .width('80%')
        .onClick(() => {
          this.pageInfos.pushPathByName('Page6253', '');
        })
        .margin({top: 10, bottom: 10})
      Button('push Dialog01')
        .width('80%')
        .onClick(() => {
          this.pageInfos.pushPathByName('Dialog01', '');
        })
        .margin({top: 10, bottom: 10})
    }
    .title('Page01')
  }
}

@Component
struct Dialog01 {

  @Consume('pageInfos') pageInfos: NavPathStack;

  build() {
    NavDestination() {
      Stack() {
        Column()
          .width('100%')
          .height('100%')
          .backgroundColor(Color.Gray)
          .opacity(0.1)
          .onClick(() => {
            this.pageInfos.pop();
          })
        // Add controls for business processing
        Column() {
          Text('Dialog01')
            .fontSize(30)
            .fontWeight(2)
          Button('push Page01')
            .width('80%')
            .onClick(() => {
              this.pageInfos.pushPathByName('Page6253', '');
            })
            .margin({top: 10, bottom: 10})
          Button('push Dialog01')
            .width('80%')
            .onClick(() => {
              this.pageInfos.pushPathByName('Page6253', '');
            })
            .margin({top: 10, bottom: 10})
          Button('pop')
            .width('80%')
            .onClick(() => {
              this.pageInfos.pop();
            })
            .margin({top: 10, bottom: 10})
        }
        .padding(10)
        .width(250)
        // .backgroundColor(Color.White)
        .borderRadius(10)
      }
    }
    // .backgroundColor("rgba(0,0,0,0)")
    .hideTitleBar(true)
    // Set the mode property of this NavDestination to DIALOG
    .mode(NavDestinationMode.DIALOG)
  }
}

@Entry
@Component
struct Index {
  @Provide('pageInfos') pageInfos: NavPathStack = new NavPathStack()
  isLogin: boolean = false;

  @Builder
  PagesMap(name: string) {
    if (name == 'Page6253') {
      Page6253()
    } else if (name == 'Dialog01') {
      Dialog01()
    }
  }

  build() {
    Navigation(this.pageInfos) {
      Button('push Page6253')
        .width('80%')
        .onClick(() => {
          this.pageInfos.pushPathByName('Page6253', '');
        })
    }
    .mode(NavigationMode.Stack)
    .titleMode(NavigationTitleMode.Mini)
    .title('主页')
    .navDestination(this.PagesMap)
  }
}
  • 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.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
  • 106.
分享
微博
QQ
微信
回复
2024-12-26 16:30:20
相关问题
HarmonyOS 如何设置颜色透明
1651浏览 • 1回复 待解决
如何将背景颜色设置透明
3614浏览 • 1回复 待解决
HarmonyOS 有没有设置颜色透明度的方法
1546浏览 • 1回复 待解决
HarmonyOS page和WebView无法设置透明
1229浏览 • 1回复 待解决
Span设置backGroundColor不生效是为什么?
1217浏览 • 1回复 待解决
HarmonyOS color颜色怎么指定透明度?
1687浏览 • 1回复 待解决