HarmonyOS 如何实现从透明色的渐变?

使用linearGradient中, colors的设置使用argb颜色,透明度通道的设置无效,如

Line()
  .width('100%')
  .height(1.5)
  .linearGradient({
    angle: 90,
    colors: [[0xffffff, 0.0], [0xffaa22, 0.5], [0xffffff, 1.0]]
  })
和
Line()
  .width('100%')
  .height(1.5)
  .linearGradient({
    angle: 90,
    colors: [[0x00ffffff, 0.0], [0xffffaa22, 0.5], [0x00ffffff, 1.0]]
  }) 

这两个效果没有区别, 该如何实现从透明色的渐变?

阅读 557
1 个回答

建议使用\#00ffffff写法,请参考以下示例:

@Entry
@Component
struct TextPickerDialogExample {
  build() {
    Column() {

      Line()
        .width('100%')
        .height(1.5)
        .margin({top:100})
        .linearGradient({
          angle: 90,
          colors: [[0xffffff, 0.0], [0xffaa22, 0.5], [0xffffff, 1.0]]
        })
      Text('----------------------------------------')
      Line()
        .width('100%')
        .height(1.5)
        .linearGradient({
          angle: 90,
          colors: [['#00ffffff', 0.0], ['#ffffaa22', 0.5], ['#00ffffff', 1.0]]
        })
    }.height('100%')
    .backgroundColor(Color.Black)
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进