Xamarin.forms: [Android] Regression HorizontalTextAlignment of Entry control no longer works

Created on 22 Mar 2018  Â·  21Comments  Â·  Source: xamarin/Xamarin.Forms

Description

HorizontalTextAlignment not working for entry

Note
When testing Entry inside the Xamarin.ControlGallery project the HorizontalTextAlignment for entry works fine but when you use HorizontalTextAlignment in a Xamarin Forms project then HorizontalTextAlignment doesn't work so most likely one of the custom renderers in the ControlGallery project is giving the illusion that this is working

Steps to Reproduce

  1. Add Entry control to page
  2. Set "Center" or "End" to HorizontalTextAlignment property
  3. Run

Expected Behavior

Placeholder and text can be placed to Center or End.

Actual Behavior

Placeholder and text are allways in Start position

Basic Information

  • Version with issue: 3.0.0.296286-pre2
  • Last known good version: 2.5.**
  • IDE: Visual Studio 2017 (PC)
  • Platform Target Frameworks:

    • Android: Target 8.1

  • Android Support Library Version: 27.0.2
  • Nuget Packages:
  • Affected Devices: Test device: samsung galaxy a5 2017 android 7.0
regression Android bug

Most helpful comment

The core of this issue came around during the RTL updates because of a change to use TextAlignment instead of gravity for aligning the text. But the TextAlignment API only has any effect when you have RtlSupport enabled for an android application

I have a PR checked in for a fix but for now I can think of two workarounds

  • implement a custom renderer for all the Entry elements and just set the gravity of the TextView yourself
  • or if you set application android:supportsRtl="true" in your Manifest then that should cause text to start centering again

All 21 comments

Works fine for me in testing. Can you give me a repro?

I have too, May be it happen when use custom renderer.

No, I have default Entry control without custom renderer.

I am trying create new empty project, but I can't because I can't update Xamarin.Android.Support packages (NU1107: Version conflict detected for Xamarin.Android.Support.Compat. Reference the package directly from the project to resolve this issue.) Working with Xamarin is incredibly annoying. All the time something falls off and breaks down. By the way I was forced to do update to 3.0.0.296286-pre2 because after update to last stable version I got the wrong button's view. After them I tried to do downgrade, but I got any errors too and I could not do it. I had no choice but to update Xamarin to 3.0.0.296286-pre2. (Facepalm). Now my buttons are look right, but I've problem with entries (bang head against the wall)

Sorry to hear you're having issues. Can you attach a repro ? Maybe from that I can also see why your having issues getting things updated and see the issue you've originally referenced

At last I managed to update the packages and I did repro. I had uploaded repro project to my google drive: link
Also I'll attach screenshoot from my device:
screenshot_20180329-170956 1

Hmmm yea this looks like a 3.0 regression :-/ thank you for the repro. I see it works fine in 2.5.1 though

@AlexeyStarkov looks like this is fixed on the 3.0.0 branch . I'll close this for now and once the next pre-release comes out if you're still having issues let me know

@PureWeen
Thank you for help. I'll update XF.

I'm facing this issue with v3.0.0.446417, is there a later version I should be looking out for?

@kyluke do you have a reproduction we can see by chance? I had done my tests with the one included and it all seemed well.

There's another PR coming later on
https://github.com/xamarin/Xamarin.Forms/pull/2215

That addresses some additional measuring issues in Android but not sure if that will address what you are seeing

@PureWeen I'll see if I can pop some sample code up on here, I suspect you've already solved my problem. That PR (https://github.com/xamarin/Xamarin.Forms/pull/2215), is that in v3.0.0.446417 or is that still to come?

@kyluke Still to come

@PureWeen, okay cool. Is there an ETA on that?

@kyluke can you try
https://www.nuget.org/packages/Xamarin.Forms/3.1.0.469394-pre1

See if that fixes your issue?

@PureWeen I think the PR you mentioned fixes a different problem than the one in this issue alltogether ☹ Have you looked into the repro project posted by @AlexeyStarkov ? Please note that the repro has this line in MainPage.xaml:
<Entry BackgroundColor="Green" Placeholder="0000 0000 0000 0000" PlaceholderColor="AliceBlue" HorizontalTextAlignment="Center" VerticalOptions="Center"/> So basically the text (and placeholder) of the Entry should be horizontally centered. This does work with Xamarin Forms 2.5.1, but it does NOT work with Xamarin Forms 3.XX. I have tested this with the current stable version 3.0.0.482510 as well as 3.1.0.469394-pre1.
Could you please reopen the issue until this is fixed? Please also see this Forum post regarding the same problem: https://forums.xamarin.com/discussion/126338/horizontaltextalignment-not-working-after-3-0-update

Please see these screenshots:

Xamarin Forms 2.5.1 (good):
image

Xamarin Forms 3.XX (bad):
image

The core of this issue came around during the RTL updates because of a change to use TextAlignment instead of gravity for aligning the text. But the TextAlignment API only has any effect when you have RtlSupport enabled for an android application

I have a PR checked in for a fix but for now I can think of two workarounds

  • implement a custom renderer for all the Entry elements and just set the gravity of the TextView yourself
  • or if you set application android:supportsRtl="true" in your Manifest then that should cause text to start centering again

Issue still exist in 3.0.0.530893

@tmt242001 have you tried rebuilding / delete bin and obj folders? 3.0.0.530893 seems to resolve the issue for me

Yes, It works now. Tested on 3.0.0.550146 (rebuild after deleting bin and obj folders)

This appears to be back in 4.3.0.99121.

Text="{Binding ServerIPAddress, Mode=TwoWay}"
BackgroundColor="White" Margin="16,0,16,0" HorizontalTextAlignment="Center" />

Works on iOS not android. This I an Android 9 emulator screenshot:

Screenshot_1575389513

Also as an FYI I tried adding the android:supportsRtl="true" to my Android manifest and that did not resolve the problem.

Never mind -- added it to the Application tag and it fixed it. Here is the line from the Manifest

I have the same issue with 4.4.0.991265 version. As @gceaser mentioned with support rtl it's working but we need a real fix because I don't need the right to left layout support in my app.

Was this page helpful?
0 / 5 - 0 ratings