[FIXED] Xamarin Forms Entry with coloured border on Android

Issue

I have made a custom rendered entry for my app that at the minute just adds padding to the text. I would also like the border color to always be blue, even when the user focuses on the entry.
I have this code at the minute in my Android custom entry (taken from here, but it doesn’t work, it simply adds just a blue background):

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

        if (Control != null)
        {
            var view = (BlueBorderEntry)Element;
            GradientDrawable gd = new GradientDrawable();

            //Below line is useful to give border color
            gd.SetColor(global::Android.Graphics.Color.Rgb(45, 192, 232));


            this.Control.SetBackgroundDrawable(gd);
            this.Control.SetPadding(40, 40, 40, 40);


            this.Control.SetRawInputType(InputTypes.TextFlagNoSuggestions);
        }
    }

I have explored what could possibly set the border color and found:

this.Control.SetCompoundDrawables();

Which is described as:

Sets the drawables to appear to the left, above, right and below the text.

However after passing in a Drawable with the blue color, it did absolutely nothing to my entry.

I can’t seem to figure out how to get the border to be a blue color, if someone could please help me?

EDIT: I need the border to be on the bottom of the entry and about 5px thick.

Solution

I have used a work around, I added a BoxView below the entry with the same width as the Entry and a HeightRequest of 5

<customrenderers:BlueBorderEntry x:Name="username" Text="" Placeholder="Email" WidthRequest="150" Margin="35, 0, 35, 0"/>
<BoxView WidthRequest="150" HeightRequest="5" BackgroundColor="#8ad6ea" Margin="35, 0, 35, 20"/>

Answered By – Matt Ward

Answer Checked By – Pedro (FixeMe Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *