HarmonyOS 控制键盘隐藏、设置TextArea失焦

如何实现点击其它控件让TextArea失焦,让处于弹起状态的键盘隐藏呢?

HarmonyOS
2024-12-24 17:45:26
932浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zbw_apple

请参考以下代码:

@Entry
@Component
struct TextInputExample {
  @State oneButtonColor: string = '#FFC0CB'
  build() {
    Column() {
      TextArea({ placeholder: '请输入评论。。。' })
        .width('95%')
        .height(40)
        .margin(20)
        .onFocus(() => {
          console.log("TextArea获焦");
        })
        .onBlur(() => {
          console.log("TextArea失焦");
        })
      // button设置点击时能获焦
      Button('First Button')
        .backgroundColor(this.oneButtonColor)
        .width(260)
        .height(70)
        .fontColor(Color.Black)
        .focusable(true)
          // 设置点击获取焦点
        .focusOnTouch(true)
        .onFocus(() => {
          this.oneButtonColor = '#FF0000'
        })
        .onBlur(() => {
          this.oneButtonColor = '#FFC0CB'
        })
    }.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.
分享
微博
QQ
微信
回复
2024-12-24 18:43:19
相关问题
HarmonyOS RichEditor 获/问题
1090浏览 • 1回复 待解决
HarmonyOS TabContent控制显示隐藏
619浏览 • 1回复 待解决
HarmonyOS 怎么控制弹窗隐藏
340浏览 • 1回复 待解决
HarmonyOS TextArea与系统键盘的使用方式
597浏览 • 1回复 待解决
HarmonyOS web监听键盘显示隐藏
706浏览 • 1回复 待解决
HarmonyOS 监听键盘显示隐藏无效
678浏览 • 1回复 待解决