Skip to content

Instantly share code, notes, and snippets.

@hamid-shaikh
Last active January 17, 2019 08:39
Show Gist options
  • Save hamid-shaikh/0565a7aafdeb5551c0caf1de6342e839 to your computer and use it in GitHub Desktop.
Save hamid-shaikh/0565a7aafdeb5551c0caf1de6342e839 to your computer and use it in GitHub Desktop.
Label Text Alignment when Arabic text is displayed - Android
[assembly: ExportRenderer(typeof(AppLabel), typeof(AppLabelRenderer))]
namespace MyProject.Droid.Renderers
{
public class AppLabelRenderer : LabelRenderer
{
readonly Context GetContext;
public AppLabelRenderer(Context context) : base(context)
{
GetContext = context;
}
protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
{
base.OnElementChanged(e);
if (GlobalSetting.IsArabic)//Created a boolean flag to identify Language Selected by user in Core/Shared Project
{
Control.TextDirection = Android.Views.TextDirection.Rtl;
Control.Gravity = Android.Views.GravityFlags.Right;
}
else
{
Control.TextDirection = Android.Views.TextDirection.Ltr;
Control.Gravity = Android.Views.GravityFlags.Left;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment