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