W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
多態(tài)樣式
從API Version 8開始支持。后續(xù)版本如有新增內(nèi)容,則采用上角標(biāo)單獨(dú)標(biāo)記該內(nèi)容的起始版本。
從API version 9開始,該接口支持在ArkTS卡片中使用。
名稱 | 類型 | 必填 | 描述 |
---|---|---|---|
normal | ()=>void | 否 | 組件無狀態(tài)時(shí)的樣式。 |
pressed | ()=>void | 否 | 組件按下狀態(tài)的樣式。 |
disabled | ()=>void | 否 | 組件禁用狀態(tài)的樣式。 |
focused | ()=>void | 否 | 組件獲焦?fàn)顟B(tài)的樣式。 |
clicked | ()=>void | 否 | 組件點(diǎn)擊狀態(tài)的樣式。 |
- // xxx.ets
- @Entry
- @Component
- struct StyleExample {
- @State isEnable: boolean = true
- @Styles pressedStyles() {
- .backgroundColor("#ED6F21")
- .borderRadius(10)
- .borderStyle(BorderStyle.Dashed)
- .borderWidth(2)
- .borderColor("#33000000")
- .width(120)
- .height(30)
- .opacity(1)
- }
- @Styles disabledStyles() {
- .backgroundColor("#E5E5E5")
- .borderRadius(10)
- .borderStyle(BorderStyle.Solid)
- .borderWidth(2)
- .borderColor("#2a4c1919")
- .width(90)
- .height(25)
- .opacity(1)
- }
- @Styles normalStyles() {
- .backgroundColor("#0A59F7")
- .borderRadius(10)
- .borderStyle(BorderStyle.Solid)
- .borderWidth(2)
- .borderColor("#33000000")
- .width(100)
- .height(25)
- .opacity(1)
- }
- build() {
- Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) {
- Text("normal")
- .fontSize(14)
- .fontColor(Color.White)
- .opacity(0.5)
- .stateStyles({
- normal: this.normalStyles,
- })
- .margin({ bottom: 20 })
- .textAlign(TextAlign.Center)
- Text("pressed")
- .backgroundColor("#0A59F7")
- .borderRadius(20)
- .borderStyle(BorderStyle.Dotted)
- .borderWidth(2)
- .borderColor(Color.Red)
- .width(100)
- .height(25)
- .opacity(1)
- .fontSize(14)
- .fontColor(Color.White)
- .stateStyles({
- pressed: this.pressedStyles,
- })
- .margin({ bottom: 20 })
- .textAlign(TextAlign.Center)
- Text(this.isEnable == true ? "effective" : "disabled")
- .backgroundColor("#0A59F7")
- .borderRadius(20)
- .borderStyle(BorderStyle.Solid)
- .borderWidth(2)
- .borderColor(Color.Gray)
- .width(100)
- .height(25)
- .opacity(1)
- .fontSize(14)
- .fontColor(Color.White)
- .enabled(this.isEnable)
- .stateStyles({
- disabled: this.disabledStyles,
- })
- .textAlign(TextAlign.Center)
- Text("control disabled")
- .onClick(() => {
- this.isEnable = !this.isEnable
- console.log(`${this.isEnable}`)
- })
- .fontSize(10)
- }
- .width(350).height(300).margin(10)
- }
- }
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: