开发者在使用TextInput组件时,对组件的下划线使用有以下几个经典场景:
@Entry @Component struct PageOne { build() { Row() { Column() { TextInput({ placeholder: 'input your password...' }) .width('95%') .height(40) .margin(20) .type(InputType.Password) .maxLength(9) .showPasswordIcon(true) .backgroundColor('#00000000') // 设置下划线 .outline({ width: { bottom: 1 }, color: Color.Black, }); } .width('100%') } .height('100%') } }
效果预览:

@Entry @Component struct PageTwo { @State bottomColor: Color = Color.Black; build() { Row() { Column() { TextInput({ placeholder: 'input your password...' }) .type(InputType.Normal) .width('95%') .height(50) .showUnderline(true) .underlineColor({ normal: this.bottomColor, }) .onFocus(() => { setInterval(() => { this.bottomColor = this.bottomColor === Color.Red ? Color.Blue : Color.Red; }, 500); // 每500毫秒改变一次颜色 }); } .width('100%') } .height('100%') } }
效果预览:
