我该如何使用React Native默认在键盘上方添加按钮?我指的是原生键盘上的按钮(不更改键盘,只是将其作为前缀添加)。
react-native
中的KeyboardAvoidingView
组件,方法如下:import React, { Component } from 'react';
import { View, Text, KeyboardAvoidingView, TextInput } from 'react-native';
import { Header } from 'react-native-elements';
class App extends Component {
render() {
return (
<View style={{ flex: 1, backgroundColor: 'white' }}>
<Header
outerContainerStyles={{ ... }}
centerComponent={(
<Text style={{ ... }}>
Test Screen
</Text>
)}
/>
<View style={{ flex: 1 }}>
<TextInput
style={{ ... }}
value={ ... }
onChangeText={() => { }}
/>
</View>
<KeyboardAvoidingView
behavior='padding'
style={{ backgroundColor: '#4099FF' }}
>
<Text>
Toolbar
</Text>
</KeyboardAvoidingView>
</View>
);
}
}
export default App;
<View></View>
组件上使用 position:absolute
和 bottom:0
。