Do I have a solution to change the cursor color for AuroComplete
1 Answer, 1 is accepted
0
Lance | Senior Manager Technical Support
Telerik team
answered on 15 Jun 2023, 08:20 PM
Hello Hakob,
This is similar to my answer to your other forum post about changing cursor color for RadEntry, because inside the Autocomplete is a RadEntry. So, my answer to you here is going to be very similar to my answer to the RadEntry question.
publicclassMyCustomTelerikAutoComplete : Telerik.Maui.Controls.RadAutoComplete
{
protectedoverridevoidOnHandlerChanged()
{
// 1. Run the default handler logic firstbase.OnHandlerChanged();
#if ANDROID// 2. Change the cursorif (this?.Handler?.PlatformView is Telerik.Maui.Border.BorderViewGroup borderViewGroup)
{
var textInputs = borderViewGroup.GetChildrenOfType<TextInputLayout>();
var textInput = textInputs.FirstOrDefault();
if (textInput is { EditText.TextCursorDrawable: notnull })
{
textInput.EditText.TextCursorDrawable.SetColorFilter(new PorterDuffColorFilter(Android.Graphics.Color.Red, PorterDuff.Mode.Darken));
}
}
#elif __IOS__#endif
}
}
Here's what the above code looks like at runtime:
Empowering Self-Discovery
Before I send this, I wanted to share a pro-tip with you. When you are not sure about what the data type is you're working with, you can always put a temporary line of code and run the app real quick:
That would have gotten you the Telerik.Maui.Border.BorderViewGroup for the RadAutoComplete Handler (because the autocomplete is a bunch of inner controls)... then you can look inside the view group for the EditText.
However, what if you want to also writ this for iOS/MacCatalyst? Using my trick, you would have seen the following in your output:
Viola! How you write the rest of the code is up to you, there are a wide variety of way to work with .NET iOS APIs. Here's just one example
if (this.Handler?.PlatformView is Telerik.Maui.Border.TKBorderView borderView)
{
var textField = borderView.FindDescendantView<UITextField>();
}
Conclusion
Here's Android and iOS combined in the same implementation:
publicclassMyCustomTelerikAutoComplete : Telerik.Maui.Controls.RadAutoComplete
{
protectedoverridevoidOnHandlerChanged()
{
// 1. Run the default handler logic firstbase.OnHandlerChanged();
// 2. Change the cursor#if ANDROIDif (this.Handler?.PlatformView is Telerik.Maui.Border.BorderViewGroup borderViewGroup)
{
var textInputs = borderViewGroup.GetChildrenOfType<TextInputLayout>();
var textInput = textInputs.FirstOrDefault();
if (textInput is { EditText.TextCursorDrawable: notnull })
{
textInput.EditText.TextCursorDrawable.SetColorFilter(new PorterDuffColorFilter(Android.Graphics.Color.Red, PorterDuff.Mode.Darken));
}
}
#elif __IOS__
if (this.Handler?.PlatformView is Telerik.Maui.Border.TKBorderView borderView)
{
// Find the UITextField inside the AutoComplete's layout
var textField = borderView.FindDescendantView<UITextField>();
// Do your customizations
if(textField != null)
textField.TintColor = UIColor.Red;
}
#endif
}
}
Regards,
Lance | Manager Technical Support
Progress Telerik