HarmonyOS 如何改变光标位置

HarmonyOS  如何改变光标位置。

HarmonyOS
2024-09-24 12:08:29
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
superinsect

示例如下:

// xxx.ets  
@Entry  
@Component  
struct TextInputExample {  
  controller: TextInputController = new TextInputController()  
  @State inputValue: string = ""  
  
  // 自定义键盘组件  
  @Builder CustomKeyboardBuilder() {  
    Column() {  
      Row(){  
        Button('x').onClick(() => {  
          // 关闭自定义键盘  
          this.controller.stopEditing()  
        })  
        Button('光标').onClick(() => {  
          // 关闭自定义键盘  
          this.controller.caretPosition(2)  
        })  
      }  
      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 }).height('48vp')  
    }  
  }  
}
分享
微博
QQ
微信
回复
2024-09-24 15:58:27
相关问题
HarmonyOS RichEditor光标位置异常问题
136浏览 • 1回复 待解决
设置TextInput组件光标位置在起点
690浏览 • 1回复 待解决
基于自定义键盘设置光标位置
679浏览 • 1回复 待解决
HarmonyOS TextInput如何隐藏光标
123浏览 • 1回复 待解决
HarmonyOS 如何隐藏TextInput中的光标
57浏览 • 1回复 待解决
HarmonyOS 如何改变this指向
25浏览 • 1回复 待解决
HarmonyOS如何动态改变图标
610浏览 • 1回复 待解决
HarmonyOS 如何改变图标icon颜色
127浏览 • 1回复 待解决
HarmonyOS 输入法光标控制
312浏览 • 1回复 待解决
HarmonyOS 如何实现拖动改变ListItem顺序
462浏览 • 1回复 待解决
HarmonyOS 如何获取文本框中光标高度
47浏览 • 1回复 待解决
HarmonyOS RichEditor 添加图片后光标消失
208浏览 • 1回复 待解决
HarmonyOS 输入框光标移位监听
220浏览 • 1回复 待解决
HarmonyOS如何修改气泡位置
367浏览 • 1回复 待解决