Use `Custom renderer` to apply `border` on `Label` control. Create `class` `ExLabel` in `xamarin.forms` Shared project. Like below
public class ExLabel : Label
{
public ExLabel()
{
}
}
Now in `android` project implement add `Custom renderer` class and use `ExLabel` there
[assembly: ExportRenderer(typeof(ExLabel), typeof(ExLabelRenderer))]
namespace Chemichals.Droid.Renderers
{
public class ExLabelRenderer : LabelRenderer
{
Context context;
public ExLabelRenderer(Context context) : base(context)
{
this.context = context;
}
protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.SetBackground(ResourcesCompat.GetDrawable(Resources, Resource.Drawable.BorderLabel, null));
}
}
}
}
Now in `Resource -> Drawable` `folder` add below `BorderLabel.xml` file
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="@android:color/white" />
<stroke android:width="1dip" android:color="#66B4E6"/>
</shape>
In xamarin forms shared project's `xaml file` use `ExLabel` instead of `Label`, you will see a border on it.
You can set a shape drawable (a rectangle) as background for the view.
<TextView android:text="Some text" android:background="@drawable/back"/>
And rectangle drawable back.xml (put into res/drawable folder):
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="@android:color/white" />
<stroke android:width="1dip" android:color="#4fa5d5"/>
</shape>
You can use `@android:color/transparent` for the solid color to have a transparent background.
You can also use padding to separate the text from the border.
for more information see: http://developer.android.com/guide/topics/resources/drawable-resource.html