Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native Text Input Android Cursor/Caret and Text Cursor Color

I'm struggling with the React Native Text Input component and can't seem to find a way to change the color of the cursor and the text selection indicators on android.

The official documentation only lists a prop for the selection color (the highlighted background of the text).

Is there any way to do this without changing it globally? And if changing it globally is the correct way to do it, what is the best way to do it? Change it in the styles.xml? React-Native crashes when i try to change that.

like image 695
nath354 Avatar asked May 17 '18 20:05

nath354


People also ask

How do I change cursor color in text input in react native?

window. tintColor = [UIColor redColor]; // Here is your color. Or, adding the below code after [self. window makeKeyAndVisible]; , you can change the tint color of TextInput/UITextField.

How do I change the cursor color in react?

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 I change the size of my cursor in react native?

step 1: Create editext_cursor. xml and place it under res->drawable directory. and here you can change the width to whatever you want.

What is input field in Caret?

A caret (sometimes called a "text cursor") is an indicator displayed on the screen to indicate where text input will be inserted. Most user interfaces represent the caret using a thin vertical line or a character-sized box that flashes, but this can vary.


1 Answers

We Can change it for android in styles.xml file located at android/app/src/main/res/values/styles.xml

But, before that it's better to stop the NodeJS server, then make the below changes

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

        <!-- Customize your theme here. -->
        <item name="colorControlActivated">@android:color/white</item>
    </style>

</resources>

You can also add custom hex color codes by adding a colors.xml file in the same directory with the following code.

<resources>
    <color name="primaryRed">#EB1E27</color>
</resources>

Then in your styles.xml file you can reference that color with @color/primaryRed. Which would look something like this:

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

        <!-- Customize your theme here. -->
        <item name="colorControlActivated">@color/primaryRed</item>
    </style>
</resources>

Once this is done, It is recommended to Re-build the project with Android studio, if the build is successful, then you can run react-native run-android.

like image 51
Godwin Vinny Carole Avatar answered Nov 15 '22 00:11

Godwin Vinny Carole