这是我的 React Native 代码: 从“反应”导入反应; import { View, StyleSheet, TextInput } from "react-native";
const UselessTextInput = () => {
const [text, onChangeText] = React.useState("");
const [number, onChangeNumber] = React.useState(null);
return (
<View>
<TextInput
style={styles.input}
onChangeText={onChangeText}
value={text}
/>
</View>
);
};
const styles = StyleSheet.create({
input: {
height: 40,
margin: 12,
borderWidth: 1,
},
});
export default UselessTextInput;
答案 0 :(得分:1)
onKeyPress={({ nativeEvent }) => {
if (nativeEvent.key === 'Backspace') {
alert("Backspace is pressed")
}
}}
尝试小吃here
注意:在 Android 上只处理来自软键盘的输入,而不处理硬件键盘输入。
soft keyboard
(屏幕键盘或软件键盘)就像手机或平板电脑屏幕上的键盘一样。
hardware keyboard
(外部键盘)类似于带 USB 的键盘(Android 支持),但您可以忽略它。