How to specify Japanese encoding for a Label?

Dan ny 21 Reputation points
2021-06-01T23:43:56.707+00:00

When I attempt to display the kanji 直 in a Label on Android, it gets displayed as Chinese instead of Japanese

Chinese vs. Japanese

(see here for more examples)

According to this post, Android chooses the default based on whether or not the user has Japanese installed as a language.

Is there any way to tell it to pick the Japanese encoding?

Developer technologies | .NET | Xamarin
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2021-06-02T03:14:39.81+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    What is the language of the Android device you run your project?

    If the language is Japanese like this screenshot.

    101450-111.png

    When I set the "直" in the xaml.

       <Label Text="直" HorizontalTextAlignment="Center" TextColor="White" FontSize="36"/>  
    

    His running result is correct. So here is no need to change it in xaml. It will change it in the actual android device.

    101581-image.png

    You want to use TextView.SetTextLocale() in custom renderer, you can try to following code.

       [assembly: ExportRenderer(typeof(Label), typeof(MyLabel))]  
       namespace JanpanLabel.Droid  
       {  
           class MyLabel : LabelRenderer  
           {  
               public MyLabel(Context context) : base(context)  
               {  
               }  
               protected override void OnElementChanged(ElementChangedEventArgs<Label> e)  
               {  
                   base.OnElementChanged(e);  
                   var kanji = Control as TextView;  
                  kanji.TextLocale= Locale.Japan;  
               }  
           }  
       }  
    

    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 additional answers

Sort by: Most helpful

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.