自定义键盘, 切换到系统键盘后,系统键盘无法调起

自定义键盘键盘包含 中文键盘,切换到系统键盘。

使用相关api后,键盘已经切换到系统键盘了,但是系统键盘无法弹出,需要再次点击 输入框,系统键盘才会弹出。

HarmonyOS
2024-10-08 11:43:42
442浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
superinsect

可以先将输入框的focusable属性或enabled属性设置为false使其变为失焦状态再获焦即可唤起系统键盘

参考:

@Entry  
@Component  
struct Index {  
  @State keyboardType: number = 0  
  @State text: string = ''  
  controller: TextInputController = new TextInputController()  
  @State flag:boolean = true  
  build() {  
    Column() {  
      Button('Set caretPosition 1')  
        .onClick(() => {  
          this.controller.caretPosition(1)  
        })  
      TextInput({ text: this.text, placeholder: 'input your word...', controller: this.controller })  
        .placeholderFont({ size: 14, weight: 400 })  
        .width(320).height(40)  
        .fontSize(14).fontColor(Color.Black)  
        .backgroundColor(Color.White)  
        .id('TextInput')  
        .customKeyboard(this.keyboardType == 0 ? this.buildCustomKeyboard() : null)  
        .defaultFocus(true)  
        .focusable(this.flag)  
    }  
    .backgroundColor(Color.Red)  
    .expandSafeArea([SafeAreaType.SYSTEM])  
    .width('100%')  
    .height('100%')  
  }  
  
  @Builder buildCustomKeyboard() {  
    Column({space: 10}) {  
      Row({space: 10}) {  
        Text('600')  
          .onClick(()=>{  
            this.text = '600'  
          })  
        Text('800')  
          .onClick(()=>{  
            this.text = '800'  
          })  
      }  
      .justifyContent(FlexAlign.SpaceAround)  
      .width('100%')  
      .layoutWeight(1)  
      Row({space: 10}){  
        Text('确认')  
          .onClick(()=>{  
            this.controller.stopEditing()  
          })  
        Text('中文')  
          .onClick(()=>{  
            this.keyboardType = 1  
            this.flag = false  
            setTimeout(()=>{  
              this.flag = true  
              focusControl.requestFocus('TextInput')  
            }, 2000)  
          })  
      }  
      .justifyContent(FlexAlign.SpaceAround)  
      .width('100%')  
      .layoutWeight(1)  
    }  
    .backgroundColor(Color.White)  
    .height(200)  
  } }
  • 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.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
分享
微博
QQ
微信
回复
2024-10-08 15:37:26
相关问题
HarmonyOS Web页面如何调起自定义键盘
1000浏览 • 1回复 待解决
HarmonyOS 自定义键盘
1017浏览 • 1回复 待解决
HarmonyOS TextInput自定义键盘
1304浏览 • 1回复 待解决
小程序示例自定义键盘
1088浏览 • 1回复 待解决
HarmonyOS TextInput自定义键盘问题
1557浏览 • 1回复 待解决
HarmonyOS 自定义键盘弹起遮住输入框
1465浏览 • 1回复 待解决
HarmonyOS 键盘顶部添加自定义组件
964浏览 • 1回复 待解决
基于自定义键盘设置光标位置
1363浏览 • 1回复 待解决
HarmonyOS 数字自定义键盘如何实现
1255浏览 • 1回复 待解决
HarmonyOS TextInput绑定自定义键盘问题
1363浏览 • 1回复 待解决