组件enable和stateStyles组合 enable设置true还是false。展示的都是false的样式
@Entry
@Component
struct Index {
@State message: string = 'Hello World';
build() {
RelativeContainer() {
Text(this.message)
.id('HelloWorld')
.fontSize(20)
.fontWeight(FontWeight.Bold)
.alignRules({
center: { anchor: '__container__', align: VerticalAlign.Center },
middle: { anchor: '__container__', align: HorizontalAlign.Center }
})
.height(48)
.borderRadius(8)
.borderWidth(0.5)
.textAlign(TextAlign.Center)
.stateStyles({
normal: {
.borderColor(Color.Black)
.fontColor(Color.Black)
},
disabled: {
.borderColor("#FFD4A3")
.fontColor("#FFD4A3")
},
}).enabled(true)
}
.height('100%')
.width('100%')
}
}
stateStyles 只能支持所有组件可用的通用属性,字体颜色建议使用attributeModifier来实现。参考链接:
https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-universal-attributes-attribute-modifier-V5