Rounded border in Xamarin.Forms.Entry keeps getting cut

My rounded border entry is getting cut out. The code in my custom renderer makes the rounded corners have larger widths than my set border width. How do I remove the increased border width on the corners?

Screenshot of entry Code:

var y = (float)CalculateResolutionScaling(25);
var x = new float[] { y, y, y, y, y, y, y, y };
var z = new RectF(35, 35, 35, 35);
var shape = new ShapeDrawable(new global::Android.Graphics.Drawables.Shapes.RoundRectShape(x, null, null));
shape.Paint.SetStyle(Paint.Style.Stroke);
shape.Paint.StrokeWidth = (float)CalculateResolutionScaling(control.BorderWidth * 2.75);
Control.Background = shape;
shape.Paint.Color = control.BorderColor.ToAndroid();

2 answers

  • answered 2018-11-14 06:04 G.hakim

    All you have to do is add this to your styles:

    RoundedCorner.xml

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <corners android:radius="10dp" />
    <padding
        android:bottom="3dp"
        android:left="0dp"
        android:right="0dp"
        android:top="3dp" />
    <gradient
        android:angle="90"
        android:endColor="@color/White"
        android:startColor="@color/White" />
    <stroke
        android:width="1dp"
        android:color="@color/Gray" />
    </shape>
    

    Then use it something like this:

     Control.Background = ResourcesCompat.GetDrawable(this.Resources, Resource.Style.RoundedCorner, null);
    

    In case you want to change the colour of the Corner just change the stroke colour in the XML above.

    If you have any queries feel free to revert.

  • answered 2018-11-14 10:03 Nitin Malik

    we can achieve rounded corner entry in xamarin.forms without a custom render. you can use a Frame to create rounded corner effect.