Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing textColor of <TextInput/> in ReactNative

I wish to change the text Color & placeholder textcolor in an android react native app:

render: function() {
return (
  <View>
    <TextInput
      placeholder='Add Credit'
      placeholderTextColor='ffffff'
      textAlign='center'
    />
  </View>
);
},
var styles = StyleSheet.create({


creditInput: {
    backgroundColor: "#3f51b5",
    color: "#ffffff", //Expecting this to change input text color

},

(referencing: https://facebook.github.io/react-native/docs/textinput.html#content)

placeholderTextColor and backgroundColor change as expected, but not the input text color. Am I using the wrong attribute, or is this a react-native/android bug?

like image 885
user1618840 Avatar asked Nov 14 '15 06:11

user1618840


People also ask

How do I change TextInput color in react-native?

To change color of the placeholder adds props called placeholderTextColor = "grey".

How do you give styling to TextInput react-native?

TextInput basics You can make your element look even better like so: const styles = StyleSheet. create({ input: { borderColor: "gray", width: "100%", borderWidth: 1, borderRadius: 10, padding: 10, }, }); In the piece of code above, we styled the text box's border and gave it some padding.

How do you change color of TextBox in React?

Change the Color of the TextBox Based on its Value in React TextBox component. You can change the color of the TextBox by validating its value using regular expression in the keyup event for predicting the numeric values as demonstrated in the following code sample.


2 Answers

I can confirm it works on iOS and does not on Android (at least for React Native 0.14.2).

This issue was submitted a few days ago (see https://github.com/facebook/react-native/issues/3742).
It should be fixed, but only in the latest prerelease version (v0.15.0-rc).

like image 139
Almouro Avatar answered Sep 23 '22 10:09

Almouro


Add your style to your TextInput component and it would work I guess!

 render: function() {
return (
  <View>
    <TextInput
      style={styles.creditInput}
      placeholder='Add Credit'
      placeholderTextColor='ffffff'
      textAlign='center'
    />
  </View>
);
},
var styles = StyleSheet.create({


creditInput: {
    backgroundColor: "#3f51b5",
    color: "#ffffff", //Expecting this to change input text color

},
like image 42
Leonardo BALLAND Avatar answered Sep 22 '22 10:09

Leonardo BALLAND