We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Unable to change Cursor Color for devices using API 29 (Q)+

Devices that run Android's API 29 (Q)+ require a new way of changing the cursor color. Android devices now use one line of code instead of using the 3 lines of code found in the custom renderer class here: https://www.syncfusion.com/kb/11608/how-to-change-the-cursor-color-in-xamarin-forms-text-input-layout?_gl=1*1rqhr1j*_ga*MTkxOTIwNzE5NC4xNjU5MzkwMzk2*_ga_WC4JKKPHH0*MTY3MDA3MjQzMC4xMTIuMS4xNjcwMDcyNzYxLjAuMC4w&_ga=2.97185814.8011882.1669640507-1919207194.1659390396

If you try to run the code above on android devices using API 29 (Q)+ the application will crash when loading the page that uses the custom renderer. This is the new way to change cursor color's for android devices:

public class MyEditorRenderer : EditorRenderer
public MyEditorRenderer(Context context) : base(context)

        protected override void OnElementChanged(ElementChangedEventArgs<Editor> e)
            if (Build.VERSION.SdkInt >= BuildVersionCodes.Q)
                Control.SetTextCursorDrawable(Resource.Drawable.my_cursor); //This API Intrduced in android 10
                IntPtr IntPtrtextViewClass = JNIEnv.FindClass(typeof(TextView));
                IntPtr mCursorDrawableResProperty = JNIEnv.GetFieldID(IntPtrtextViewClass, "mCursorDrawableRes", "I");
                JNIEnv.SetField(Control.Handle, mCursorDrawableResProperty, Resource.Drawable.my_cursor);

 To my knowledge, Syncfusion's custom controls (ex// SfAutoComplete, SfComboBox, etc.) don't yet support this "SetTextCursorDrawable" method. The iOS version still works perfectly fine for Syncfusion's custom controls but until this "SetTextCursorDrawable" method exists for SfAutoCompleteRenderer and SfComboBoxRenderer, I won't be able to change the cursor colors for Syncfusion's custom controls in my android application.



1 Reply

VV Vijayakumar Viswanathan Syncfusion Team December 5, 2022 03:26 PM UTC

Hi Bryson,

Thanks for contacting Syncfusion support.

Query: I won't be able to change the cursor colors for Syncfusion's custom controls (SfAutoComplete, SfComboBox) in my android application.

SfAutoComplete and SfComboBox support the SetTextCursorDrawable method by using the GetAutoEditText method in the renderer class. We have prepared a sample for your reference, please get the sample from the attachment. 

Please let us know if you have any further queries.


Vijayakumar V

Attachment: CustomCursor_1f016680.zip

Live Chat Icon For mobile
Up arrow icon