3
votes

Is there a way to scale a button to it's text or align the text left? I have created a static method that allows me to set a generic theme for my buttons. I know you can use LayoutOptions.Start to make the button go to the left of the page.

public static void DefaultButtonTheme(Button button)
{ 
    //previous code
    .
    .
    button.HorizontalOptions = LayoutOptions.Start;
}

However, for text smaller than a certain amount of letters it is center of the button.

See image below.

enter image description here

1
To align a button's text to the left, I see 2 solutions. You can actually use a grid instead of a button, make the grid look like a button and make it clickable. This way, in the grid, you'll be able to align the text to the left of the cell. You can also create your own subclass of the Button class, and then create a custom renderer for this subclass. There you have plenty of properties and you should be able to find the one you need to align the text to the left, because I think it's not possible with a standard button.Anto Maniscalco

1 Answers

1
votes

I have investigated a bit this behaviour and I have found that this error appears on Android but not on UWP. I have also tried to use MinimumWidthRequest="0" without result.

So as Anto Maniscalco said you should create a custom control and then overwrite the Android render using android:minHeight="0dp" as you can see in the following link. It seems that Google decided by default to a minimum size for this control.

I hope this can help you.