android - 关闭键盘后 React Native TextInput 仍然具有焦点(TextInput 中的光标)

标签 android react-native

在关闭键盘或按其他地方后,如何摆脱文本输入中的光标?

这就是我所有的 TextInput:

<TextInput
  style={styles.searchBar}
  onChangeText={null}
  placeholder={'What are you searching for?'}
  underlineColorAndroid="transparent"
/>

最佳答案

我知道这个问题有点老了,但只要改进 Martin 的回答你就可以做到:

componentDidMount(){
  Keyboard.addListener('keyboardDidHide', this._forceLoseFocus);
}

<TextInput ref={(component) => this._textInput = component}/>

_forceLoseFocus = () => {
  this._textInput.blur();
}

测试并使用 React Native 0.55.4

关于android - 关闭键盘后 React Native TextInput 仍然具有焦点(TextInput 中的光标),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40775216/

相关文章:

android - 无法从 Eclipse 启动虚拟设备

javascript - 使用 React Native 创建单例类

android - React Native - 调试适配器进程意外终止

react-native - 使用 Native Base Toast 显示来自 Redux 操作的错误

Javascript — 如何将多个元素分配给一个对象?

javascript - 文本未在 View 内显示

android - 如何在 Android 中不使用 webview 显示网页

android - 蓝牙广播

java - Django 更新到 1.6 后,Android http post 请求返回 403

android - 从 ReSTLet 响应中获取文件