Why message text in Acr.UserDialogs toast displaced to bottom (Android)

Issue

I use Acr.UserDialogs library to show toast in my Xamarin Android project. When I use both icon and action button message text displaced to bottom

enter image description here

How can I fix it?

Solution

You could look at the source code of the Acr.UserDialogs https://github.com/aritchie/userdialogs/blob/45d4842648fdb01686e7493131cae66c30bcc975/src/Acr.UserDialogs/Platforms/Android/UserDialogsImpl.cs#L189

sb.SetSpan(new ImageSpan(drawable, SpanAlign.Bottom), 0, 1, SpanTypes.ExclusiveExclusive);

This means that the image is aligned with the bottom of the text, so when the image is higher than the text, it will appear that the text is tilted downward.

If you want to let them be vertically centered,you need to modify it´╝îobviously that doesn’t work.

So you could consider writing your own Snackbar to achieve this effect, refer to its source code https://github.com/aritchie/userdialogs/blob/45d4842648fdb01686e7493131cae66c30bcc975/src/Acr.UserDialogs/Platforms/Android/UserDialogsImpl.cs#L124.

Answered By – Leo Zhu – MSFT

Leave a Comment