【HarmonyOS NEXT】API 10手机升级到Canary2版本后,自定义密码弹框无法自动弹起

【关键字】

自定义密码弹框 / 弹起 / enableKeyboardOnFocus / textinput

【问题描述】

API 10手机升级到Canary2版本(API 11)后,自定义密码弹框无法自动弹起。

API 10的示例代码:

cke_464.png

API 10的效果是textinput的enableKeyboardOnFocus这个方法如果设置为true,则键盘会自动弹起;如果设置为false,则键盘不会自动弹起。

【解决方案】

建议使用如下代码:

// xxx.ets
@Entry
@Component
struct TextInputExample {
controller: TextInputController = new TextInputController()
@State inputValue: string = ""

// 自定义键盘组件
@Builder CustomKeyboardBuilder() {
Column() {
Button('x').onClick(() => {
// 关闭自定义键盘
this.controller.stopEditing()
})
Grid() {
ForEach([1, 2, 3, 4, 5, 6, 7, 8, 9, '*', 0, '#'], (item:number|string) => {
GridItem() {
Button(item + "")
.width(110).onClick(() => {
this.inputValue += item
})
}
})
}.maxCount(3).columnsGap(10).rowsGap(10).padding(5)
}.backgroundColor(Color.Gray)
}

build() {
Column() {
TextInput({ controller: this.controller, text: this.inputValue })
// 绑定自定义键盘
.customKeyboard(this.CustomKeyboardBuilder()).margin(10).border({ width: 1 })
.enableKeyboardOnFocus(true)
.defaultFocus(true)
}
}
}

参考文档:https://gitee.com/openharmony/docs/blob/master/zh-cn/release-notes/changelogs/OpenHarmony_4.1.3.2/changelogs-default-focus.md

关键是添加:.defaultFocus(true)

  • 10
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值