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

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

阅读 545
1 个回答

解决措施

Button默认背景色挡住渐变颜色设置,需要将背景色backgroundColor设置成全透明才能正常加载渐变。

代码示例

@Entry 
@Component 
struct Index { 
  build() { 
    Button('test') 
      .width(200) 
      .height(50) 
      .backgroundColor('#00000000') 
      .linearGradient({ 
        angle: 90, 
        colors: [[0xff0000, 0.0], [0x0000ff, 0.3], [0xffff00, 1.0]] 
      }) 
  } 
}

参考链接

Button

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进