为TextInput组件对齐占位符文本的最佳方式是什么?我已经try 使用下面描述的样式组件.似乎没有这样的财产.

render() {
    return (
        <View style={styles.container}>
             <TextInput
                style={styles.textInput}
                onChangeText={(text) => this.setState({
                    username: text
                })}
                placeholder='Add Username'
             />
      </View>
    );
}

}

const styles = StyleSheet.create({
 container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
 },
 textInput: {
    height: 40,
    width: 200,
    justifyContent: 'center',
    alignItems: 'center',
    alignSelf: 'center',
    borderColor: 'gray',
    borderWidth: 1,
 }

});

推荐答案

textAlign: 'center'添加到文本输入样式中.

React-native相关问答推荐

使用FETCH发送BLOB/文件时为空

一旦我关闭应用程序,Json struct 就会发生变化

Error: Invariant Violation: Touchable child must either be native or forward setNativeProps to a native component stack

Jest 遇到了带有 react-native 的意外令牌

React-Native:无法从我的 android 应用程序打开设备设置

React-Native 是单线程执行还是多线程执行?

如何在StackNavigator 中实现自定义标题图标?

react-native app.js index.js

使用 react-native 设置 Select 器的高度

如何在 react-native 中在子级和父级之间传递数据?

可以在没有 await 关键字的情况下调用异步函数吗?

React Native 中的全屏图像

在 React Native 中无法滚动到 ScrollView 的底部

如何从 React Native-App 中的 res/drawable-folder 加载图像?

react-native fetch 和基本身份验证

React Native 将状态中的数组值应用为 Picker 项

仅链接字体的方法

React Native:如何将 的高度和宽度设置为 容器?

如何在 React Native 中创建拖放操作?

如何在 react-native 中为带有图标的按钮建模