防止系统在响应本机中按下TextInput时显示键盘

问题描述 投票:0回答:2

我想在按下输入字段时显示我的自定义键盘组件。我想完全避免触发系统默认键盘。

我曾尝试在onFocus上关闭键盘,但这会触发键盘,然后关闭键盘。

 <TextInput
     placeholder="type here"
     onFocus={Keyboard.dismiss}
 />

我已经把TextInput包裹在TouchableWithoutFeedback中,但是这个解决方案不起作用。

<TouchableWithoutFeedback
    onPress={() => Keyboard.dismiss()}
    accessible={false}
>
    <View>
        <TextInput placeholder="type here" />
    </View>
</TouchableWithoutFeedback>

任何想法我怎么能达到期望的结果?

react-native keyboard textinput
2个回答
0
投票

在项目的(android> app> src> main)文件夹中打开AndroidManifest文件,然后添加:

android:windowSoftInputMode="stateHidden"

到您的活动标签这样:

<activity
    android:name=".MainActivity"
    android:label="@string/app_name"
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
    android:windowSoftInputMode="stateHidden">

0
投票

您可以在Android上使用showSoftInputOnFocus,请参阅文档:https://facebook.github.io/react-native/docs/textinput#showsoftinputonfocus

您的情况与在连接外部键盘时避免显示键盘的情况相同(在iPad上是常见的。

© www.soinside.com 2019 - 2024. All rights reserved.