Search code examples
xamlxamarinmauitext-alignment

.NET MAUI - HorizontalTextAlignment="Center" is not working on Android


I've converted a project from Xamarin to .Net MAUI. MAUI has many issues, but one of the most annoying is the fact that HorizontalTextAlignment set to Center is not working in Android. For labels that are only a single line the regular HorizontalAlignment is working, but for multiple line labels it is not a working solution:

enter image description here

In the screenshot the two header labels are centered using HorizontalAlignment on the VisualElement, but for the longer text below this is not working. Event though the label element is centered, the text inside is not center aligned.

Does anyone have a solution?

P.S. HorizontalTextAlignment is working in iOS, and it is also working in my Android emulator when I manipulate it in Hot Reload.


Solution

  • Turns out this was an issue because I upgraded a xamarin project to Maui. Somehow in the android mainifest the value android:supportsRtl="true" is then not set on the application element like this:

    <application android:networkSecurityConfig="@xml/network_security_config" android:icon="@mipmap/icon" android:label="YourAppName" android:supportsRtl="true">
    

    Thanks to @ewerspej