What is the best way to align the placeholder text for TextInput component? I have already attempted to use the styles component as described below. There doesn't seem to be a property for this.
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, } });
In order to display hint or placeholder in centered align, we need to use css style-sheet property this is textAlign: 'center'.
In most of the browsers, placeholder texts are usually aligned in left. The selector uses text-align property to set the text alignment in the placeholder. This selector can change browser to browser.
Add textAlign: 'center'
to your textInput style.
Add textAlign={'center'}
as a property to the TextInput component
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With