gpt4 book ai didi

android - KeyboardDidShow/Hide 事件在具有 adjustResize 设置的 Android 上不起作用

转载 作者:行者123 更新时间:2023-11-29 00:03:15 31 4
gpt4 key购买 nike

我正在尝试使用 React Native 在 Android 上捕获键盘显示/隐藏事件。我陷入了死胡同。

这是我的 list 设置:

<activity
android:launchMode="singleTop"
android:name=".MainActivity"
android:screenOrientation="portrait"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>
</intent-filter>
</activity>

这是我的 RN 组件:

import React, {Component} from 'react';
import {
View,Keyboard
} from 'react-native';

export default class KeyboardAwareComponent extends Component {
componentDidMount() {
Keyboard.addListener("keyboardDidShow",()=>{
console.log("Show event");
})
}

render() {
return <View />
}
}

非常感谢您提前:)

最佳答案

以下是直接来自文档的一些事件。

keyboardWillShow

键盘显示

键盘会隐藏

键盘隐藏

keyboardWillChangeFrame

keyboardDidChangeFrame

import React, { Component } from 'react';
import { Keyboard, TextInput } from 'react-native';

class Example extends Component {
componentWillMount () {
this.keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', this._keyboardDidShow);
this.keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', this._keyboardDidHide);
}

componentWillUnmount () {
this.keyboardDidShowListener.remove();
this.keyboardDidHideListener.remove();
}

_keyboardDidShow () {
alert('Keyboard Shown');
}

_keyboardDidHide () {
alert('Keyboard Hidden');
}

render() {
return (
<TextInput
onSubmitEditing={Keyboard.dismiss}
/>
);
}
}

关于android - KeyboardDidShow/Hide 事件在具有 adjustResize 设置的 Android 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48026028/

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