[SOLVED] TextInput placeHolder Alignment

Issue

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,
 }

});

Solution

Add textAlign: 'center' to your textInput style.

Answered By – Daniel Basedow

Answer Checked By – Pedro (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published.