Add bottom line in android custom renderer code?

261 views Asked by At

I know the default DatePicker already has a bottom line, but I'm trying to add a bottom line to the DatePicker in the custom renderer code (for some purpose).

I can set a full border of my GradientDrawable object by myGradientDrawable.SetStroke(3, myColor); but I don't know how to add only the bottom line so anyone can help me please?

1

There are 1 answers

0
Wilson Vargas On

Try this:

public class CustomPickerRenderer : PickerRenderer
{
    public CustomPickerRenderer(Context context) : base(context)
    {
    }

    private AlertDialog alert;
    private CustomPicker element;
    private int selectedIndex;

    public LayerDrawable AddPickerStyles(string imagePath)
    {
        ColorDrawable borderColorDrawable = new ColorDrawable(Xamarin.Forms.Color.FromHex("#43addf").ToAndroid());
        ColorDrawable backgroundColorDrawable = new ColorDrawable(Xamarin.Forms.Color.FromHex("#7e1b80").ToAndroid());

        Drawable[] drawables = new Drawable[]
        {
            borderColorDrawable, backgroundColorDrawable
        };

        LayerDrawable layerDrawable = new LayerDrawable(drawables);
        layerDrawable.SetLayerInset(1, 0, 0, 0, 5);

        return layerDrawable;
    }

    protected override void OnElementChanged(ElementChangedEventArgs<Picker> e)
    {
        base.OnElementChanged(e);

        element = (CustomPicker)this.Element;

        if (Control != null && this.Element != null)
        {
            Control.Background = AddPickerStyles(element.Image);
        }
    } 

}