虚拟键盘覆盖了文本输入区域,导致无法看到正在输入的内容。如何避免这种情况?(我尝试使用KeyboardAwareScrollView,但它仍然会覆盖文本输入区域)另外一个问题是,我的styles.container属性出现了错误——justifyContent和alignItems应该放在ScrollView属性中——我不知道怎么做——我是React Native的新手。
使用 KeyboardAvoidingView ,也是同样的事情:
render() {
return (
<KeyboardAwareScrollView>
<View style={styles.container} >
<TextInput
style={styles.input}
underlineColorAndroid="transparent"
placeholder="username"
placeholderTextColor="#00bcd4"
autoCapitalize="none"
secureTextEntry={true}
onChangeText={username => this.setState({ username })}
/>
<View style={styles.btnContainer}>
<TouchableOpacity style={styles.userBtn} onPress={() => this.Login(this.state.email, this.state.password)}>
<Text style={styles.btnTxt}>Login</Text>
</TouchableOpacity>
</View>
</View>
</KeyboardAwareScrollView>
使用 KeyboardAvoidingView ,也是同样的事情:
render() {
return (
// <View style={styles.container} >
<KeyboardAvoidingView behavior="padding" style={styles.container}>
<Text style={styles.heading} >Welcome to SelfCare !</Text>
<Image
style={{width: 200, height: 200, marginBottom: 40}}
source={require('./src/images/icon.png')}
/>
<TextInput
style={styles.input}
underlineColorAndroid="transparent"
placeholder="Email"
placeholderTextColor="#00bcd4"
autoCapitalize="none"
onChangeText={email => this.setState({ email })}
/>
<TextInput
style={styles.input}
underlineColorAndroid="transparent"
placeholder="Password"
placeholderTextColor="#00bcd4"
autoCapitalize="none"
secureTextEntry={true}
onChangeText={password => this.setState({ password })}
/>
<View style={styles.btnContainer}>
<TouchableOpacity style={styles.userBtn} onPress={() => this.Login(this.state.email, this.state.password)}>
<Text style={styles.btnTxt}>Login</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.userBtn} onPress={() => this.SignUp(this.state.email, this.state.password)}>
<Text style={styles.btnTxt}>Sign Up</Text>
</TouchableOpacity>
</View>
</KeyboardAvoidingView>
// </View>
);
}
}
return (
) `
- Suman Shaw