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光标位置异常问题
1190浏览 • 1回复 待解决
设置TextInput组件光标位置在起点
1648浏览 • 1回复 待解决
基于自定义键盘设置光标位置
1600浏览 • 1回复 待解决
HarmonyOS TextInput如何隐藏光标
765浏览 • 1回复 待解决
HarmonyOS 如何改变this指向
601浏览 • 1回复 待解决
HarmonyOS 如何隐藏TextInput中的光标
858浏览 • 1回复 待解决
HarmonyOS如何动态改变图标
1338浏览 • 1回复 待解决
HarmonyOS 如何改变图标icon颜色
940浏览 • 1回复 待解决
HarmonyOS 输入法光标控制
1472浏览 • 1回复 待解决
HarmonyOS 如何获取文本框中光标高度
892浏览 • 1回复 待解决
HarmonyOS 如何实现拖动改变ListItem顺序
949浏览 • 1回复 待解决
HarmonyOS如何修改气泡位置
968浏览 • 1回复 待解决
HarmonyOS RichEditor 添加图片后光标消失
908浏览 • 1回复 待解决
HarmonyOS 输入框光标移位监听
1130浏览 • 1回复 待解决