react-native - 如何在 React Native 中将 TextInput 放在屏幕底部?

标签 react-native react-native-android

我制作了一个聊天应用程序,我想将 TextInput 放在页面底部,但我无法做到。如果我尝试 position: 'absolute' + bottom: 0 显示为空。我想我的风格有弹性问题,我不确定。

这是我的 MessageScreen 代码:

render() {
    return (
      <Wallpaper>
        <KeyboardAvoidingView behavior='padding'>
          <View>
          <TextInput
            style={styles.input}
            onChangeText={text => this.setState({ message: text })}
           // value={this.state.email}
            placeholderTextColor='white'
            underlineColorAndroid='transparent'
          />
            <Button onPress={this.send} title='SEND' />
              </View>
               </KeyboardAvoidingView>
      </Wallpaper>
    );
  }
}

const styles = StyleSheet.create({
  text: {
    color: 'white',
    fontWeight: 'bold',
    backgroundColor: 'transparent',
    paddingLeft: 25
  },
  input: {
    backgroundColor: 'rgba(255, 255, 255, 0.4)',
    width: DEVICE_WIDTH ,
    height: 40,
    color: '#ffffff'
  },
 image: {
    width: 40,
    height: 40
  }
});

这是壁纸:
render() {
    return (
      <Image style={styles.picture} source={require('src/components/images/wallpaper.png')}>
        {this.props.children}
      </Image>
    );
  }
}

const styles = StyleSheet.create({
  picture: {
    flex: 1,
    width: undefined,
    height: undefined,
    resizeMode: 'cover'
  }
});

最佳答案

尝试这个。

<View style={styles.container}>
 <KeyboardAvoidingView 
   style={{position: 'absolute', left: 0, right: 0, bottom: 0}}
   behavior="position"
 >
  <TextInput
    style={styles.input}
    onChangeText={text => this.setState({ message: text })}
    // value={this.state.email}
    placeholderTextColor='white'
    underlineColorAndroid='transparent'
  />
  <Button onPress={this.send} title='SEND' />
 </KeyboardAvoidingView>
</View>

可以找到工作示例 here

关于react-native - 如何在 React Native 中将 TextInput 放在屏幕底部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45876884/

相关文章:

javascript - 在运行下一个突变之前重置值

ios - 为什么我的 React Native 桥接 iOS 组件不起作用?

javascript - 将参数从屏幕传递到 Header 组件 react 导航

react-native - 使用 React-Native 在图像周围环绕文本

react-native - React-Native无法解析配置 ':classpath'的所有工件

android - 为 react-native native android 方法编写单元测试

react-native - 突出显示 React-Native FlatList 中的选定项目

android - 如何在 react-native 中使用 leaflet.js

reactjs - 传递给解析器的不是有效的 GraphQL DocumentNode。您可能需要使用 'graphql-tag' 或其他方法将您的操作转换为文档

react-native - 导航 ('DrawerOpen' )不适用于 createSwitchNavigator 和 createStackNavigator