Javascript 如何在 textinput 中集中文本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30012089/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 04:29:15  来源:igfitidea点击:

How to centralize text in textinput

javascriptreact-native

提问by Tyler.z.yang

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

一个简短的问题。
有没有办法在 react-native 中集中文本Textinput

Here is the markup in jsx:

这是 jsx 中的标记:

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

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

在styles.input 中,尝试添加textAlign:"center",它不起作用。

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

与将 alignAlign 作为属性添加到标记相同。有人可以帮我一个忙吗?谢谢。

采纳答案by tkers

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

这个错误已经存在一段时间了,但看起来很快就会合并一个修复程序:https: //github.com/facebook/react-native/pull/772

回答by kalimsayyad

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

您应该使用 inputText 道具将文本居中对齐,如下所示

textAlign={'center'}

And it will look like

它看起来像

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

回答by tkers

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

android-onlytextAlignVertical也可能是解决方案的必要组件。另请参阅:如何在本机反应中正确对齐文本输入?