当我关闭键盘或在其他地方按下时,如何消除文本输入框中的光标?
这是我对于TextInput所拥有的全部内容:
<TextInput
style={styles.searchBar}
onChangeText={null}
placeholder={'What are you searching for?'}
underlineColorAndroid="transparent"
/>
当我关闭键盘或在其他地方按下时,如何消除文本输入框中的光标?
这是我对于TextInput所拥有的全部内容:
<TextInput
style={styles.searchBar}
onChangeText={null}
placeholder={'What are you searching for?'}
underlineColorAndroid="transparent"
/>
componentDidMount(){
Keyboard.addListener('keyboardDidHide', this._forceLoseFocus);
}
<TextInput ref={(component) => this._textInput = component}/>
_forceLoseFocus = () => {
this._textInput.blur();
}
已测试并与React Native 0.55.4兼容。
我猜如果你在Android上用Android-Back-Button关闭键盘,你将不得不检测该按钮的按下或检测键盘何时消失。要检查键盘:
import {
Keyboard
} from 'react-native';
class MyClass extends Component{
//...
componentDidMount () {
Keyboard.addListener('keyboardDidHide', callback)
}
//...
}
在你的回调函数中,你可以调用this.refs.yourInput.blur();
如果你想尝试使用检测后退按钮按下,但我不确定它是否适用于检测键盘消失。