HarmonyOS 如何实现线性控制字体背景颜色的透明度

Text("立即登录")
  .textAlign(TextAlign.Center)
  .fontColor(Color.White)
  .fontSize(12)
  .height(24)
  .textAlign(TextAlign.Center)
  .margin({ right: 10, })
  .alignRules({
    top: { anchor: "__container__", align: VerticalAlign.Top },
    bottom: { anchor: "__container__", align: VerticalAlign.Bottom },
    right: { anchor: "__container__", align: HorizontalAlign.End }
  })
  .borderRadius(50)
  .padding({
    top: 4,
    bottom: 4,
    left: 8,
    right: 8
  })
  .linearGradient({
    angle: 45,
    colors: [['#9589F4', 0], ['#B6ADFB', 1]]
  })
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.

目前实现了一个带有背景的Text UI

现在有一个逻辑是,需要他拥有,整体从 100%~0%透明度变化的能力(背景和文字)要怎么实现?

HarmonyOS
2024-12-24 17:25:11
2318浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
fox280

colors使用rgba试试,请参考下方代码:

@Entry
@Component
struct Index {
  build() {

    Column(){
      Text("立即登录")
        .textAlign(TextAlign.Center)
        .fontColor(Color.White)
        .fontSize(12)
        .height(24)
        .textAlign(TextAlign.Center)
        .margin({ right: 10, })
        .alignRules({
          top: { anchor: "__container__", align: VerticalAlign.Top },
          bottom: { anchor: "__container__", align: VerticalAlign.Bottom },
          right: { anchor: "__container__", align: HorizontalAlign.End }
        })
        .borderRadius(50)
        .padding({
          top: 4,
          bottom: 4,
          left: 8,
          right: 8
        })
        .linearGradient({
          angle: 45,
          colors: [['rgba(149,137,244,1)', 0], ['rgba(149,137,244,0.66)', 0.33],['rgba(149,137,244,0.33)', 0.66],['rgba(149,137,244,0)', 1]]
        })
    }
  }
}
  • 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.
分享
微博
QQ
微信
回复
2024-12-24 20:04:20
相关问题
HarmonyOS 如何设置背景透明度
684浏览 • 1回复 待解决
HarmonyOS 如何设置颜色透明度
1660浏览 • 1回复 待解决
自定义颜色透明度如何实现
1007浏览 • 1回复 待解决
HarmonyOS color颜色怎么指定透明度
1689浏览 • 1回复 待解决
HarmonyOS 有没有设置颜色透明度方法
1558浏览 • 1回复 待解决
HarmonyOS 如何实现透明度渐变效果
705浏览 • 1回复 待解决
SideBarContainer如何设置透明度
3004浏览 • 1回复 待解决
背景透明度问题解决方案
1754浏览 • 1回复 待解决
HarmonyOS Image UI 如何设置图片透明度
725浏览 • 1回复 待解决
设置子窗口透明度未生效
2242浏览 • 1回复 待解决