Tyler.z.yang
Tyler.z.yang

Reputation: 2450

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.

Upvotes: 43

Views: 78340

Answers (3)

kalimsayyed
kalimsayyed

Reputation: 1143

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" />

Upvotes: 84

user657199
user657199

Reputation:

The android-only textAlignVertical may also be a necessary component of the solution. See also: How to align text input correctly in react native?

Upvotes: 3

tkers
tkers

Reputation: 938

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

Upvotes: 6

Related Questions