I have a problem with centering a TextInput
, and at the same time keep the placeholder visible. I want the text to start where the placeholder starts (centered).
On IOS it's working but on android it's only partly visible.
Result on IOS: IOS placeholder
Result on android: Android placeholder
This is my code:
render() {
return (
<View style={styles.containerStyle}>
<TextInput
underlineColorAndroid='transparent'
placeholder={"Placeholder "}
placeholderTextColor={"grey"}
maxLength={6}
style={{ fontSize: 30, color: "black",
justifyContent: "center", }}
onChangeText={this.props.onChangeText}
value={this.props.value.toUpperCase()}
/>
</View>
);
}
}
const styles = {
containerStyle: {
flexDirection: 'row',
backgroundColor: "#fff",
borderRadius: 5,
borderWidth: 1,
shadowColor: "#000",
elevation: 2,
marginLeft: 5,
marginRight: 5,
alignItems: 'center',
justifyContent: "center"
}
};
Use flex:1
in your TextInput
style
<View style={styles.containerStyle}>
<TextInput
underlineColorAndroid='transparent'
placeholder={"Placeholder "}
placeholderTextColor={"grey"}
maxLength={6}
style={{ flex:1, fontSize: 30, color: "black",
justifyContent: "center", }}
onChangeText={this.props.onChangeText}
value={this.props.value.toUpperCase()}
/>
</View>