Is there a way to style the textInput in react-native android? Like change the underlineColor when selected and the cursor color?
import React from 'react' import { View, Text, TouchableHighlight, TextInput, Dimensions, StyleSheet } from 'react-native' import { StackNavigator } from 'react-navigation' import { colors } from '../styles/colors' let windowSize = Dimensions. get('window') export default class TestScreen extends React.
TextInput needs value that it is the value that is gonna be shown inside the TextInput. And to update that value you use onChangeText that is gonna call whatever function you specify every time the text into the TextInput change.
To change the React Native text input cursor color, we can set the selectionColor prop to the cursor color. to set selectionColor to 'green' to set the cursor color on the text input to green.
focus textinput in class component examplecreateRef(); let's understand with the example of create ref of textinput in class component. export default ReactNativeComponents; The above example also added auto navigate the second textinput when the first input fired submit an event.
As of React Native version 0.21, there is still no way to style the cursor color via view props. I have successfully styled the cursor color by adding a custom style to my app theme.
You will want to place this code in the styles.xml
file, which is located in the android folder of your React project, at android/app/src/main/res/values/styles.xml
.
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- typical material style colors -->
<item name="colorPrimary">@color/kio_turquoise</item>
<item name="colorPrimaryDark">@color/kio_hot_pink</item>
<!-- sets cursor color -->
<item name="colorControlActivated">@android:color/black</item>
</style>
</resources>
Note that this style is global, and will set the cursor color for all Android TextInput
views in your React Native app.
For the underline color you can use underlineColorAndroid
property: https://github.com/facebook/react-native/blob/master/Libraries/Components/TextInput/TextInput.js#L290
See example: https://github.com/facebook/react-native/blob/master/Examples/UIExplorer/TextInputExample.android.js#L222
For cursor color there is no such property exposed at the moment. You can always use custom android theme for your app if you want to change that globally for all textviews in your app (read more here: http://developer.android.com/guide/topics/ui/themes.html)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With