美文网首页
页面包含scrollView和TextInput,当键盘弹起来的

页面包含scrollView和TextInput,当键盘弹起来的

作者: sunny635533 | 来源:发表于2022-09-28 19:17 被阅读0次

    android的手机,页面包含scrollView和TextInput,当键盘弹起来的时候会挡住TextInput。
    原生键盘模式是“ android:windowSoftInputMode="adjustResize"”。
    用了如下方法解决这个问题,虽然不够完美:

    componentDidMount() {
           this.keyboardDidShow = Keyboard.addListener("keyboardDidShow", e => {
               console.log("====== e.endCoordinates.height:" + e.endCoordinates.height)
               this.setState({ KeyboardHeight: e.endCoordinates.height })
           });
           this.keyboardDidHide = Keyboard.addListener("keyboardDidHide", e => {
               this.setState({ KeyboardHeight: 0 })
           });
       }
    
       componentWillUnmount() {
           this.keyboardDidShow.remove();
           this.keyboardDidHide.remove();
       }
    
    render() {
           return (<View style={styles.container}>
               {Platform.OS == "android" && <View style={{
                   height: this.state.KeyboardHeight,
                   backgroundColor: "rgba(0,0,0,0.5)"
               }} />}
               ....
               </View>
    

    希望有更好的方法,欢迎指点。

    相关文章

      网友评论

          本文标题:页面包含scrollView和TextInput,当键盘弹起来的

          本文链接:https://www.haomeiwen.com/subject/dgwcartx.html