HarmonyOS 2个TextInput控件,当TextInput输入都有值时,改变Text的背景色

HarmonyOS 2个TextInput控件,当TextInput输入都有值时,改变Text的背景色。

HarmonyOS
2024-11-28 10:17:16
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
shlp

参考代码:

@Entry 
@Component 
struct TextInputDemo { 
  @State message: string = 'Hello World'; 
  @State text1: string = '' 
  @State text2: string = '' 
  @State changeColoor : boolean=false 
  controller: TextInputController = new TextInputController() 
 
  build() { 
    Column(){ 
      Text(this.message) 
        .id('HelloWorld') 
        .fontSize(50) 
        .fontWeight(FontWeight.Bold) 
        .alignRules({ 
          center: { anchor: '__container__', align: VerticalAlign.Center }, 
          middle: { anchor: '__container__', align: HorizontalAlign.Center } 
        }) 
        .backgroundColor(this.changeColoor ? Color.Red: '') 
      TextInput({ text: this.text1, placeholder: 'input your word1...', controller: this.controller }) 
        .width('95%') 
        .height(40) 
        .margin(20) 
        .onChange((value: string)=>{ 
          this.text1 = value 
          if(this.text2 && this.text1){ 
            this.changeColoor = true 
          }else{ 
            this.changeColoor = false 
          } 
 
        }) 
      TextInput({ text: this.text2, placeholder: 'input your word2...', controller: this.controller }) 
        .width('95%') 
        .height(40) 
        .margin(20) 
        .onChange((value: string)=>{ 
          this.text2 = value 
          if(this.text1 && this.text2){ 
            this.changeColoor = true 
          }else { 
            this.changeColoor = false 
          } 
        }) 
    } 
    .height('100%') 
    .width('100%') 
  } 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
分享
微博
QQ
微信
回复
2024-11-28 15:41:47
相关问题
TextInput按压态背景色如何修改
3273浏览 • 1回复 待解决
HarmonyOS 如何获取TextInput输入
803浏览 • 1回复 待解决
HarmonyOS 弹窗自带背景色
512浏览 • 1回复 待解决
HarmonyOS 关于开屏背景色
602浏览 • 1回复 待解决
如何设置WebView背景色
1638浏览 • 1回复 待解决
如何设置窗口背景色
2614浏览 • 1回复 待解决
HarmonyOS 如何设置渐变背景色
2292浏览 • 1回复 待解决
取消点击textinput背景高亮样式
1214浏览 • 1回复 待解决
HarmonyOS Select组件背景色如何设置
600浏览 • 1回复 待解决
TextInput怎么输入中文
4030浏览 • 0回复 待解决
Button组件如何设置渐变背景色
3759浏览 • 1回复 待解决
HarmonyOS TextInput如何换行输入
862浏览 • 1回复 待解决