鸿蒙Button组件如何设置渐变背景色

当我想给Button组件设置渐变的时候,却发现一直不生效,直到看到文档里说的“设置颜色渐变需先设置backgroundColor为透明色。”

下面给个案例

@Entry
@Component
@Preview
struct Index {
  build() {
    Column() {
      Button('登录')
        .width(300)
        .margin({ top: 20, bottom: 20 })
        .height(48)
        .backgroundColor(Color.Transparent)// 设置颜色渐变需先设置backgroundColor为透明色。
        .linearGradient({
          angle: 180,
          colors: [[0x58B1FF, 0.0], [0x258FFF, 1]] })

      Button('test')
        .width(300)
        .height(50)
        .backgroundColor('#00000000')
        .linearGradient({
          angle: 90,
          colors: [[0xff0000, 0.0], [0x0000ff, 0.3], [0xffff00, 1.0]]
        })
    }.padding(30)

  }
}

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值