Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-native android Styling textInput

Is there a way to style the textInput in react-native android? Like change the underlineColor when selected and the cursor color?

like image 876
Nishanth Shankar Avatar asked Sep 24 '15 03:09

Nishanth Shankar


People also ask

How do you give styling to TextInput React Native?

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.

How do I change TextInput value in React Native?

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.

How do I change the cursor color in TextInput React Native?

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.

How do you focus TextInput in React Native?

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.


2 Answers

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.

like image 196
Kio Krofovitch Avatar answered Sep 18 '22 17:09

Kio Krofovitch


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)

like image 31
kzzzf Avatar answered Sep 22 '22 17:09

kzzzf