Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextInput placeHolder Alignment

Tags:

react-native

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,  }  }); 
like image 311
Shivam Sinha Avatar asked May 21 '16 02:05

Shivam Sinha


People also ask

How do you align placeholders in React Native?

In order to display hint or placeholder in centered align, we need to use css style-sheet property this is textAlign: 'center'.

How do you set placeholder position?

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.


2 Answers

Add textAlign: 'center' to your textInput style.

like image 199
Daniel Basedow Avatar answered Sep 21 '22 11:09

Daniel Basedow


Add textAlign={'center'} as a property to the TextInput component

like image 30
Nguyễn Phúc Avatar answered Sep 21 '22 11:09

Nguyễn Phúc