Xamarin.Forms – change cursor’s color – Android

This code (https://github.com/officialdoniald/Xamarin.Forms.CustomControls/blob/master/XamarinForms.CustomControls/XamarinForms.CustomControls.Android/CustomRenderer/CustomEntryRenderer.cs ) :

IntPtr IntPtrtextViewClass = JNIEnv.FindClass(typeof(TextView));

IntPtr mCursorDrawableResProperty = JNIEnv.GetFieldID(IntPtrtextViewClass, “mCursorDrawableRes”, “I”);

will change the cursor’s color. If you want to really change the color of the cursor, you have to create in the Resources/Drawable folder a my_cursor.xml file: https://github.com/officialdoniald/Xamarin.Forms.CustomControls/blob/master/XamarinForms.CustomControls/XamarinForms.CustomControls.Android/Resources/drawable/my_cursor.xml

<shape xmlns:android=”http://schemas.android.com/apk/res/android” android:shape=”rectangle”>
<solid android:color=”@color/colorCursors”></solid>
<size android:width=”2dp” />

@color/colorCursors is a color from the Resources/values/color.xml. If you don’t have this file, just create it: https://github.com/officialdoniald/Xamarin.Forms.CustomControls/blob/master/XamarinForms.CustomControls/XamarinForms.CustomControls.Android/Resources/values/colors.xml

<?xml version=”1.0″ encoding=”utf-8″?>
<color name=”launcher_background”>#FFFFFF</color>
<color name=”colorPrimary”>#3F51B5</color>
<color name=”colorPrimaryDark”>#303F9F</color>
<color name=”colorAccent”>#FF4081</color>
<color name=”colorCursors”>#000000</color>

<color name=”colorCursors”>#000000</color> here can you gain the color of the cursor.

3 thoughts on “Xamarin.Forms – change cursor’s color – Android”

  1. I’m not that much of a online reader to be honest but your blogs really nice, keep it up! I’ll go ahead and bookmark your site to come back in the future. All the best|

  2. I’m impressed, I have to admit. Տeldom do I encounteг a
    blog that’s equally еducative and amusіng, and let me tell you, you’ve hit the nail
    on the head. The issuе iѕ something too few men and
    ԝomen are speaking іntelligently about. I am very haρpy
    that I came acгoss this during my hunt for something reɡarⅾing this.

Leave a Reply

Your email address will not be published. Required fields are marked *