@Styles標(biāo)簽
@Styles標(biāo)簽跟Android style類(lèi)似,分為全局和組件內(nèi)
全部定義
@Styles function xx {}
組件內(nèi)定義
@Styles xxx{}
引用時(shí)組件內(nèi)高于全局的
/**
* 全局styles樣式
*/
@Styles function globalFancy(){
.width(100)
.height(150)
.backgroundColor(Color.Pink)
}
//頁(yè)面入口
@Entry
@Component
struct StylesPage{
@State heightNum:number = 100
@Styles selfFancy(){
.width(120)
.height(this.heightNum)
.backgroundColor(Color.Yellow)
.onClick(()=>{
this.heightNum = 180
})
}
build(){
Column({space:10}){
Text("全局引用styles")
.globalFancy()
.fontSize(25)
Text("組件內(nèi)的style")
.selfFancy()
.fontSize(18)
}
}
}
@Extend
類(lèi)似于kotlin的擴(kuò)展函數(shù)
//定義
@Extend(Text) function textSizeFancy(size:number){
.fontColor(Color.Red)
.fontSize(size)
}
//使用
Text("@Extend擴(kuò)展方法").textSizeFancy(18)