@Styles 装饰器  装饰公共的样式

@Styles function  setStyle(){
  .width('90%').height(140)
  .borderRadius(10)
  .backgroundColor("#8000FF00")
  .border({width:1,color:"#333333"})
}

使用:

@Builder  ItemCard(item:ItemBean){
  Row(){
    Image(item.image).height(100).width(50).objectFit(ImageFit.Contain).margin({
      left:20
    })
    Column(){
      Text(item.name).fontSize(20).fontColor($r('app.color.color_333333'))
      Text("¥"+item.price).fontSize(20).fontColor($r('app.color.color_FF0000'))
    }.margin({left:30})
  }.alignItems(VerticalAlign.Center).justifyContent(FlexAlign.Start)
  .setStyle()
}

但是style装饰器封装的属性只能是公共的属性

假如你要用textview的一些特有属性得用,这个有一个区别就是 @Extend装饰器只能用于全局的方法,不能用于组件内方法

@Extend(Text) function setTextstyle(){
  .fontSize(20).fontColor($r('app.color.color_333333'))
}

设置背景拉伸图,和.9一样的效果

鸿蒙开发进阶(HarmonyOS )ArkUI实现9图的拉伸能力场景_鸿蒙加载.9图-CSDN博客

Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐