New to Telerik UI for Xamarin? Download free 30-day trial

Change Entry Underline Color when on focus

Environment

Product Version 2021.3.915.1
Product Entry for Xamarin Cross-Platform

Description

This article shows how to change the Entry underline color on Android when the control receives focus.

Solution

You will need a Custom Renderer for Android.

  1. Entry definition:
<StackLayout>
    <input:RadEntry WatermarkText="Telerik Entry"/>
</StackLayout>
  1. Create a Custom Renderer on Android. Class CustomEntryRenderer which inherits from EntryRenderer.

In oder to change the underline color override the OnElementChanged method and inside it set color to the BackgroundTintList property:

using Android.Content;
using Android.Content.Res;
using Android.Graphics.Drawables;
using Android.Runtime;
using Android.Text;
using Android.Widget;
using ListPicker.Droid;
using Telerik.XamarinForms.Input;
using Telerik.XamarinForms.InputRenderer.Android;
using Xamarin.Forms;

[assembly: ExportRenderer(typeof(RadEntry), typeof(CustomEntryRenderer))]

namespace ListPicker.Droid
{
    public class CustomEntryRenderer : EntryRenderer
    {
        public CustomEntryRenderer(Context context) : base (context)
        {

        }

        protected override void OnElementChanged(Xamarin.Forms.Platform.Android.ElementChangedEventArgs<RadEntry> e)
        {
            base.OnElementChanged(e);

            if (this.Control != null)
            {
                this.Control.BackgroundTintList = ColorStateList.ValueOf(Android.Graphics.Color.Blue);
            }
        }
    }
}
In this article