Last active
January 17, 2019 08:39
-
-
Save hamid-shaikh/0565a7aafdeb5551c0caf1de6342e839 to your computer and use it in GitHub Desktop.
Label Text Alignment when Arabic text is displayed - Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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