1.9 KiB
1.9 KiB
title | description | type | page_title | slug | position | tags | ticketid | res_type |
---|---|---|---|---|---|---|---|---|
Change Entry Underline Color when on focus | how to change the entry underline color on android | how-to | Change Entry underline color when on focus | entry-chnage-underline-color | entry, underline color, android, xamarin, xamarin.forms | 1541339 | kb |
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.
- Entry definition:
<StackLayout>
<input:RadEntry WatermarkText="Telerik Entry"/>
</StackLayout>
- 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);
}
}
}
}