如何让 `TextInput` 在获得焦点时自动全选内容?

新手上路,请多包涵

想实现一个效果:当用户点击进入某个 TextInput 时,里面已有的内容能自动被全选,方便用户直接替换。

阅读 277
1 个回答
✓ 已被采纳
  1. 创建并绑定TextInputControllerTextInput
  2. 监听.onFocus事件(或者 .onEditChange 判断 isEditing 变为 true)。
    "3. 在焦点获取事件的回调中,使用 controller.setSelection(start, end) 方法将选区设置为覆盖整个文本内容(即从索引 0 到文本末尾)。"
推荐问题