HarmonyOS Focus进入时弹出键盘问题

​预期:进入时不弹出键盘。

实际上:弹出​。

@Component  
export struct ExpandTextComponent {  
  @State text: string = ''  
  controller: TextAreaController = new TextAreaController()  
  
  build() {  
    Column() {  
      Column({ space: 50 }) {  
        TextArea({  
          text: this.text,  
          placeholder: 'The text area can hold an unlimited amount of text. input your word...',  
          controller: this.controller  
        })  
          .id("TextArea_ID")  
          .defaultFocus(false)  
          .placeholderFont({ size: 16, weight: 400 })  
          .width(336)  
          .height(56)  
        Row() {  
          Button('open TextArea')  
            .onClick(() => {  
              sendEventByKey("TextArea_ID", 10, "")  
            })  
          Button('cloas TextArea')  
            .onClick(() => {  
              this.controller?.stopEditing()  
  
            })  
        }  
      }  
      .width('100%')  
      .height('100%')  
    }  
    .backgroundColor(Color.Orange)  
    .size({ width:'100%',height:'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.
HarmonyOS
2024-10-28 10:03:24
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zbw_apple

​给TextArea添加.enableKeyboardOnFocus(false),能否满足您的需求。

文档:

https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-textarea-V5#ZH-CN_TOPIC_0000001847209048__enablekeyboardonfocus10

根据的您的描述,以下方案能否满足您的需求​。

@Component  
export struct ExpandTextComponent {  
  @State text: string = ''  
  controller: TextAreaController = new TextAreaController()  
  // 默认不展示键盘  
  @State isShowKey: boolean = false;  
  
  aboutToAppear(): void {  
    // 根据业务需要,特殊情况下显示键盘  
    setTimeout(() => {  
      if (true) {  
        this.isShowKey = true  
        focusControl.requestFocus('TextArea_ID')  
      }  
    }, 1000)  
  }  
  build() {  
    Column() {  
      Column({ space: 50 }) {  
        TextArea({  
          text: this.text,  
          placeholder: 'The text area can hold an unlimited amount of text. input your word...',  
          controller: this.controller  
        })  
          .id("TextArea_ID")  
          .focusable(this.isShowKey)  
          .placeholderFont({ size: 16, weight: 400 })  
          .width(336)  
          .height(56)  
        Row() {  
          Button('open TextArea')  
            .onClick(() => {  
              sendEventByKey("TextArea_ID", 10, "")  
            })  
          Button('cloas TextArea')  
            .onClick(() => {  
              this.controller?.stopEditing()  
            })  
        }  
      }  
      .width('100%')  
      .height('100%')  
    }  
    .backgroundColor(Color.Orange)  
    .size({ width:'100%',height:'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.
分享
微博
QQ
微信
回复
2024-10-28 16:31:43
相关问题
HarmonyOS 键盘问题
563浏览 • 1回复 待解决
HarmonyOS键盘问题
483浏览 • 1回复 待解决
HarmonyOS web弹起键盘问题
770浏览 • 1回复 待解决
HarmonyOS TextInput调用系统键盘问题
878浏览 • 1回复 待解决
HarmonyOS TextInput自定义键盘问题
1557浏览 • 1回复 待解决
HarmonyOS TextInput绑定自定义键盘问题
1363浏览 • 1回复 待解决
HarmonyOS WebView使用自定义键盘问题
880浏览 • 1回复 待解决
HarmonyOS 输入框与软键盘问题
823浏览 • 1回复 待解决
HarmonyOS textinput键盘弹出问题
1363浏览 • 1回复 待解决
关于软键盘弹出遮挡问题
1862浏览 • 1回复 待解决
HarmonyOS键盘弹出方式
845浏览 • 1回复 待解决
HarmonyOS 如何监听键盘弹出收回?
1680浏览 • 1回复 待解决
并发问题和内存数据刷盘问题
5081浏览 • 1回复 待解决
HarmonyOS 如何监听软键盘弹出
874浏览 • 1回复 待解决
HarmonyOS TextInput如何主动弹出键盘
1080浏览 • 1回复 待解决
设置键盘弹出内容上移
1053浏览 • 1回复 待解决
HarmonyOS键盘弹出隐藏监听
786浏览 • 1回复 待解决
HarmonyOS 怎么监控键盘弹出或者收起
585浏览 • 1回复 待解决