Share via

Maui android button text not centered

Haviv Elbsz 2,071 Reputation points
Dec 8, 2022, 9:05 PM

Hi all

The text in my maui app not show exactly at
the centre of the button.

is horizontaloption = centre not works ?

the button corners are rounded is this
concerning.

Thank you very much

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,935 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,307 questions
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 79,941 Reputation points Microsoft Vendor
    Dec 9, 2022, 7:12 AM

    Hello,

    Try to add the blew padding and set width request in the button like following code.

       <Button  
                       x:Name="CounterBtn"  
                       HeightRequest="40"  
                       WidthRequest="70"  
                       CornerRadius="20"  
                       Padding="0,0,0,2"  
                       BorderColor="Black"  
                       Text="size +"  
                       HorizontalOptions="Center"  
                       />  
    

    ===========
    Update ===========

    Or you can open the style.xaml(Resources folder=> Styles.xaml) to find the <Style TargetType="Button"> tag and remove <Setter Property="Padding" Value="14,10"/> line.

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.