I've a button in xamarin forms. I want it to left align on my device. On iOS it is by default left aligned but for android it is center aligned. I tried using custom renderer for button and set it gravity to left as shown in code below but it does not work for me. Below is my code snippet of button and it's custom renderer. I've added this CustomButton in horizontal stack layout. So, my question is how to left align a button on android ?
`
public class CustomButton : Button
{
public CustomButton ()
{
}
}
var editButton = new CustomButton () {
TextColor = Color.Gray,
Text = Constants.mStringEdit,
BackgroundColor = Color.Green,
FontSize = 18,
HorizontalOptions = LayoutOptions.Start,
};
public class CustomButtonRenderer : ButtonRenderer
{
public CustomButtonRenderer ()
{
}
protected override void OnElementChanged (ElementChangedEventArgs<Button> e)
{
base.OnElementChanged (e);
Android.Widget.Button button = Control as Android.Widget.Button;
if (button != null) {
button.Gravity = GravityFlags.Left;
}
}
}
`