【问题标题】:How to avoid Soft Keyboard from pushing Buttons up in Android (iOS is OK)如何避免软键盘在 Android 中向上推按钮(iOS 可以)
【发布时间】:2020-10-19 03:44:21
【问题描述】:

在我的 react-native 应用程序中,我有一个 keyboardAwareScrollView 和下方的按钮。
不显示键盘时,ScrollView 可以正常工作,并且 Button 始终显示在屏幕底部。

但是当键盘弹出时:

  • 在 iOS 上,按钮不显示在键盘顶部(预期情况)
  • 在 Android 上,按钮浮动在键盘顶部(如下图所示)

我希望底部的按钮现在在键盘打开时显示(就像在 iOS 中一样)。

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

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

android:windowSoftInputMode="adjustPan"

android:windowSoftInputMode="adjustNothing"

【问题讨论】:

  • 你只是没有启用ios硬件键盘,否则两者都是一样的。
  • 如何启用“硬件键盘”...只有软键盘afaik。我也尝试过实体手机(不仅在模拟器上)。它在 iOS 上运行良好。

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


【解决方案1】:

这对我有用,

设置

 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>

【讨论】:

  • 嗨@imKrishh,您的回答有效,但我不得不将
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多