如何避免软键盘在Android中按下按钮(iOS正常)

时间:2020-10-19 03:44:21

标签: android react-native react-native-android

在我的本机应用程序中,我在其下面有一个keyboardAwareScrollView和Buttons。
当不显示键盘时,ScrollView可以正常工作,并且Button始终显示在屏幕底部。

但是当键盘弹出时:

  • 在iOS上,按钮未显示在键盘顶部(预期大小写)
  • 在Android上,键盘上方的按钮浮动(如下图所示)

我希望在keyBoard打开时(如在iOS中)现在显示底部的按钮。

    <View style={{flex:1}}>
        <KeyboardAwareScrollView keyboardShouldPersistTaps='handled'>
            ...
            <TextInput /> 
            ...
        </KeyboardAwareScrollView>
        <Button>Save</Button>
    </View>

answer here中所述,我尝试如下编辑AndroidManifest.xml文件。
它修复了Buttons不在键盘上方浮动的问题,但是却导致KeyboardAwareScrollView现在可以正常工作(某些项目隐藏在键盘后面)

android:windowSoftInputMode="adjustPan"

android:windowSoftInputMode="adjustNothing"

enter image description here

1 个答案:

答案 0 :(得分:0)

这对我有用,

设置

 android:windowSoftInputMode="adjustResize"

并使用react-native的KeyboardAvoidingView组件自动将视图调整为键盘

 <KeyboardAvoidingView
   behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
   style={{flex: 1}}>
   <ScrollView
     keyboardShouldPersistTaps="handled">
     ... 
     <TextInput /> 
     ...
   </ScrollView>
   <Button>Save</Button>
 </KeyboardAvoidingView>