TextView Ignores textAlignment Property

Nathan Sokalski 4,126 Reputation points
2021-06-15T04:49:14.417+00:00

My Xamarin.Android app recently started ignoring the textAlignment property of all the TextView(s). This started happening very unexpectedly in multiple places with no significant changes in code. Also, the Designer in Visual Studio 2019 still shows the correct rendering, even though the app does not. Here are screenshots of the Designer and Emulator:
105620-screenshot-2021-06-14-234745.png

105667-screenshot-1623728937.png
Here is the code for the TextView & Style Resource:

<TextView android:layout_row="0" style="@style/PopupHeaderTextViewStyle" android:textAlignment="center" android:text="Player Names"/>  

<style name="PopupHeaderTextViewStyle">  
	<item name="android:layout_width">match_parent</item>  
	<item name="android:layout_height">wrap_content</item>  
	<item name="android:textAlignment">center</item>  
	<item name="android:fontFamily">@font/arialfamily</item>  
	<item name="android:textStyle">bold</item>  
	<item name="android:textSize">30dp</item>  
	<item name="android:textColor">@color/Black</item>  
</style>  

Note that the textAlignment property is included in the Style & inline. As previously stated, this issue started occuring in all places, both static & dynamic. Because the issue started in completely unrelated places at the same time, it leads me to believe that it was not caused by my code, but I cannot figure out what could have caused the problem or how to fix it.

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,339 questions
0 comments No comments
{count} votes

Accepted answer
  1. Nathan Sokalski 4,126 Reputation points
    2021-06-16T18:40:12.073+00:00

    I think I found the solution. In the Application (the class that inherits from Application), I had to add SupportsRtl=true in the Application attribute, as follows:

    [Application(Debuggable = true, SupportsRtl = true)]
    public class ScorePadApplication : Application
    

    If SupportsRtl is set to false or not specified (which is what it was before), it ignored android:textAlignment, but now it works. I don't know why it was working before if this is necessary, but it seems to have solved the problem. Hopefully this can help anyone else that has this problem.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 74,641 Reputation points Microsoft Vendor
    2021-06-16T06:22:11.56+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    I used your code in my VS 2019 Version 16.10.0, my emulator and xaml previewer are work normally, please see the following screenshot

    106064-image.png

    You can try to delete following code in your PopupHeaderTextViewStyle

       <item name="android:layout_width">match_parent</item>  
            <item name="android:layout_height">wrap_content</item>  
    

    Then set android:layout_width and android:layout_height directly in TextView

       <TextView   
               android:layout_row="0"  
               android:layout_width="match_parent"  
               android:layout_height="wrap_content"  
               style="@style/PopupHeaderTextViewStyle"   
               android:textAlignment="center"   
               android:text="Player Names"/>  
    

    Best Regards,

    Leon Lu


    If the response is helpful, please click "Accept Answer" and upvote it.

    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.

    0 comments No comments

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.