赞
踩
textinput / enableKeyboardOnFocus / 键盘弹起
使用textinput的enableKeyboardOnFocus方法,实现键盘会自动弹起。
推荐示例代码如下:
- // 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)
- }
- }
- }

注意:请添加:.defaultFocus(true)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。