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
close icon

SfAutoComplete > Custom Renderer - Cursor Color not working (OnElementChanged)

Hello ,

i use this code

using Syncfusion.SfAutoComplete.XForms;
using Syncfusion.SfAutoComplete.XForms.iOS;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;

'[assembly: ExportRenderer(typeof(SfAutoCompleteExt), typeof(CustomAutocompleteRenderer))]
namespace xxxx.iOS.Renderers
{
    public class CustomAutocompleteRenderer : SfAutoCompleteRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs e)
        {
            base.OnElementChanged(e);

            Control.TintColor = UIColor.Purple;
        }
    }
}'

xaml:
            xmlns:controls="clr-namespace:xxxx.Controls;assembly=xxx">
   


c#
    public class SfAutoCompleteExt : SfAutoComplete
    {
    }

screenshot color is not changed on IOS simulator.

cursor color


11 Replies

HM Hemalatha Marikumar Syncfusion Team November 7, 2019 07:35 AM UTC

Hi Johannes,

Greetings from Syncfusion.

We have prepared the sample with the provided code snippet and we are afraid that we are not able to reproduce the issue from our side. Please download the tested sample in below
 
Simulator version: iPhone 11 iOS 13 

Please check with the above sample and if the issue still reproduces from your side please modify the issue reproducing sample and provide the simulator details which will be helpful for us to analyze further and provide an appropriate solution.
 
 
Regards, 
Hemalatha M. 



RK Radoslaw Kubas November 7, 2019 09:58 AM UTC

Hello,

Could you provider similar sample for Android?

Best regards,
Radek


HM Hemalatha Marikumar Syncfusion Team November 8, 2019 08:59 AM UTC

Hi Johannes, 
 
Thanks for your update. 
 
Your requirement “Change the color of cursor in SfAutoComplete in Android” has been achieved by setting the desired drawable (with desired color) to CursorDrawable of SfAutoComplete in Android as per in below code snippet. 
 
Codesnippet [C#]: 
 
  protected override void OnElementChanged(ElementChangedEventArgs<Syncfusion.SfAutoComplete.XForms.SfAutoComplete> e) 
        { 
            base.OnElementChanged(e); 
            if (Control != null) 
            { 
                IntPtr IntPtrtextViewClass = JNIEnv.FindClass(typeof(TextView)); 
                IntPtr mCursorDrawableResProperty = JNIEnv.GetFieldID(IntPtrtextViewClass, "mCursorDrawableRes", "I"); 
                JNIEnv.SetField(Control.GetAutoEditText().Handle, mCursorDrawableResProperty, Resource.Drawable.my_cursor); 
            } 
        } 
 
Codesnippet [xml]: (EntryCursorDemo.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" /> 
</shape> 
 
Note: colorCursors key holds #800090 color and its path file (EntryCursorDemo.Android/Resources/values/colors.xml) 
 
We have prepared the sample using Custom Renderer for Android. Please have the sample from the below link,

Sample Link:  https://www.syncfusion.com/downloads/support/directtrac/general/ze/ENTRYC~1-119617468

Screenshot:


 

Please check with the above sample and let us know if you have any concerns.
 
 
Regards, 
Hemalatha M. 



JM Johannes Meyer November 8, 2019 09:49 AM UTC

thanks for your help ;)


HM Hemalatha Marikumar Syncfusion Team November 11, 2019 05:30 AM UTC

Hi Johannes, 
 
Thanks for you update. 
 
Please let us know if you have any other query. 
 
Regards, 
Hemalatha M. 
 
 



EO Eric Oudin February 27, 2020 09:39 PM UTC

How would you change the color after it has been initialized?
 An example would be change theme. Select inside entry you see it looks correct. Change theme again. Select inside entry and it stays the color that it was initialized as from whenever you first selected the box. Running the same code to change the color will no longer work on the same entry once it has been drawn tot he screen once before.

I am also curious where I would find a list of drawable property names. I was able to find the cursor color from some googling but why isnt there documentation on other properties i can edit colors of the same way?

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

as an example the second parameter for that function... Where is that name coming from?

Most of all, why cant I just set it to a color I have dynamically?


AS Anandraj Selvam Syncfusion Team March 2, 2020 12:31 PM UTC

Hi Eric Oudin,   
   
Thanks for the update,   
   
Currently, we are validating the reported issue and we will update you on the complete status on 4th March 2020.   
   
Regards,   
Anand Raj S.  



AS Anandraj Selvam Syncfusion Team March 5, 2020 05:50 PM UTC

Hi Eric Oudin,    
    
Thanks for your patience,    
    
We are still validating the reported issue with high priority and we will update you on the complete status on or before 10th March 2020.    
  
We appreciate your patience until then. 
    
Regards,    
Anand Raj S.   



AS Anandraj Selvam Syncfusion Team March 11, 2020 02:30 PM UTC

Hi Eric, 
  
Thanks for your patience. 
  
On further analysis on your query, we cannot change the cursor color dynamically using drawble in Android platform. But you can change the color before the cursor drawn into the screen dynamically. We have created sample to change the cursor color before cursor drawn into screen in button click using dependecy service.Please find the sample from below link 
  
  
Please get back us, if you have any concern. 
  
Regards,
Anand Raj S.  



RG Ricardo Gomez replied to Hemalatha Marikumar November 9, 2021 07:58 PM UTC

Hi,


The fix above to change the cursor color in Android devices works fine so long as the android OS version is lower than 9, which in terms of Android.OS.BuildVersionCodes means Q -or 29.

Please provide a fix to change the cursor color in an android device where the OS version is 9 or greater, which  in terms of Android.OS.BuildVersionCodes would mean >= Q or  29.

Please provide ETA for this fix.


Thank you



SS Suganya Sethuraman Syncfusion Team November 10, 2021 07:12 AM UTC

Hi Ricardo,

We have analyzed the reported issue. We have checked the sample in Android OS version 11.0(R), but we could not be able to reproduce the issue. Please have a video for your reference,

Video: https://www.syncfusion.com/downloads/support/directtrac/general/ze/CursorColor-433642284

Please check and let us know if you have any concerns.

Regards,
Suganya Sethuraman.
 


Loader.
Live Chat Icon For mobile
Up arrow icon