这似乎是这么简单的事,我不明白我怎么没有得到这个权利,但placeholderTextColor在ReactNative的TextInput是不是做了我什么.
http://facebook.github.io/react-native/docs/textinput.html#placeholdertextcolor
<TextInput
style={styles.input}
placeholder="Foobar"
placeholderTextColor="#FFFFFF"/>
Run Code Online (Sandbox Code Playgroud)
什么也没做....
首先,我研究了其他帖子,发现这个如何在 React Native 中更改 TextInput 占位符的样式?
帖子中解决方案的问题是曾经fontStyle设置为斜体,它不会恢复到正常字体(我猜除非组件更新,否则它不能被覆盖)。这是我的代码示例
<TextInput
style={
this.state.value.length === 0
? {fontStyle: 'italic', color: 'white'} // font changed to white and italic
: {fontStyle: 'normal', color: 'black'} // font changed to black but stays italic
}
value={this.state.value}
/>
Run Code Online (Sandbox Code Playgroud)
我想出了一些技巧,通过强制TextInput更新使用forceUpdate()组件或设置组件的键,但这会导致键盘 UI 在用户键入时关闭,这对 UX 不利。
我只想对链接的帖子发表评论,但我的声誉还不够。
这是预期的行为还是我犯了任何错误?如果有人可以提供一些解释/解决方案,将不胜感激。
PS 使用最新的 React Native 在 Android 上测试