鸿蒙学习笔记
第六节 状态样式
这一小节就是组件显示,获取焦点,和按压之后会调用的方法
以按钮为例,注:Text组件似乎不能获得焦点
Button(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
.stateStyles({
//一旦看到对象,就可以用对象表达
normal : {
.backgroundColor(Color.Red)
},
focused:{//能获取到焦点
.backgroundColor(Color.Yellow)
},
pressed:{
.backgroundColor(Color.Blue)
}
})
}
下面是全代码,本网站图片上传比较难成功因此少了演示
@Entry
@Component
struct Index6 {
@State message: string = '状态样式学习'
build() {
Row() {
Column() {
TextInput()
.border({color:Color.Red,width: 6})
.margin(20)
// Button("zs,我获取了焦点")
Button(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
.stateStyles({
//一旦看到对象,就可以用对象表达
normal : {
.backgroundColor(Color.Red)
},
focused:{//能获取到焦点
.backgroundColor(Color.Yellow)
},
pressed:{
.backgroundColor(Color.Blue)
}
})
}
.width('100%')
}
.height('100%')
}
}