gpt4 book ai didi

android - 当虚拟键盘出现在 native react 中时如何自动向上滚动屏幕(在android上)

转载 作者:行者123 更新时间:2023-12-04 10:27:35 27 4
gpt4 key购买 nike

虚拟键盘覆盖了文本输入,我看不到我在输入什么。如何避免这种情况?
(我尝试使用 KeyboardAwareScrollView 但它仍然涵盖文本输入)。
我遇到的另一个问题是关于我的样式的错误。

  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>
);
}
}

keyboard covers textinput

最佳答案

如果你想让屏幕向上,你可以使用 <KeyboardAvoidingView> 而不是 <KeyboardAwareScrollView>除非您希望用户能够在键盘打开时滚动屏幕,否则它更容易实现并且执行相同的工作。behavior='padding' << 这个 Prop 是针对画面如何行动的。它还采用 [height, position] 作为值。

<View style={styles.container}>
<KeyboardAvoidingView behavior="padding">

... Your UI ...

</KeyboardAvoidingView>
</View>

或简写,您可以替换 <View><KeyboardAvoidingView>像这样:
<KeyboardAvoidingView behavior="padding" style={styles.container}>

... Your UI ...

</KeyboardAvoidingView>

关于android - 当虚拟键盘出现在 native react 中时如何自动向上滚动屏幕(在android上),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60565948/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com