Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to centralize text in textinput

One short question.
Is there a way to centralize text in react-native Textinput?

Here is the markup in jsx:

<TextInput style={styles.input} placeholder="Your Account" /> 

In styles.input, just try to add textAlign:"center", it's not working.

And same as add alignAlign to the markup as an attribute. Could anybody do me a favor? Thx.

like image 577
Tyler.z.yang Avatar asked May 03 '15 09:05

Tyler.z.yang


People also ask

How do you center text in TextField?

In the Format Text Box dialog box, click the Text Box tab. In the Vertical alignment box, select Top, Middle, or Bottom. Click OK.

How do you align text in TextInput React Native?

To align text to the top multiline TextInput with React Native, we can set the textAlignVertical style to 'top' . to add the multiline prop to make the TextInput a multiline input. We set the numberOfLines to set the text input height to 5 lines high.

How do you center text in a field in HTML?

Using the <center></center> tags One way to center text or put it in the middle of the page is to enclose it within <center></center> tags.

How do I center text in a text box CSS?

To just center the text inside an element, use text-align: center; This text is centered.


2 Answers

You should use the inputText props to align text to center as below

textAlign={'center'} 

And it will look like

<TextInput style={styles.input} textAlign={'center'} placeholder="Your Account" /> 
like image 172
kalimsayyad Avatar answered Sep 25 '22 05:09

kalimsayyad


This bug has been around for a while already, but it looks like a fix will be merged soon: https://github.com/facebook/react-native/pull/772

like image 43
tkers Avatar answered Sep 22 '22 05:09

tkers