Display Japanese instead of Chinese in text form

When displaying Japanese text in text mode, the android by default uses a Chinese font that displays incorrect characters, for example here . Setting the locale to Japanese works on the emulator, but does not work on my galaxy s3, probably because it does not support Japanese. Another solution is to set the default font from the asset, for example:

textView.setTypeface(Typeface.createFromAsset(getAssets(), "DroidSansJapanese.ttf")); 

but it looks like a coolge. Is there a way to install a font through an xml layout to one that supports japanese?

+4
source share
3 answers

Unable to install font directly in XML.

If you plan on using a lot of Japanese text elements, it may be easier to create a custom look to process it for you, which programmatically outputs the font from its constructor.

Then at any time, when you turn your own view down into XML, it will have the correct font.

+2
source

As a rule, older (Android) devices sold outside of Japan reproduce the Chinese version of kanji in Chinese. Android devices sold in Japan make the Japanese version of kanji by default. DroidSansJapanese is a Japanese headset for DroidSans and is available on AOSP. It seems that the manufacturer can choose a preference that uses the fonts provided by the supplier / supplier when displaying text during the creation of their Android assembly. Even if you change your language on a (non-standard) device (<4.1), it can still display the wrong version of characters.

If you want to localize your application for Japanese users in Japan, they will most likely have a device purchased in Japan, and therefore kanji will display correctly (provided that the manufacturer has taken the action required above). If this behavior is acceptable to you, then you do not need to make any changes. If you are creating an application targeted at users outside of Japan (for example, people who want to learn Japanese), this may not seem very good.

Japanese kanji support improved when Android 4.1 was released. This command contains some information about what has been changed. If your phone is currently using Japanese, Android should display Japanese-style kanji. I saw this behavior in action with a non-Japanese Samsung Galaxy Note 2 running Android 4.1. When I set my system language to English (UK / US), I see Chinese-style rendering by looking at the text of the kanji. However, when I set the language to ζ—₯本θͺž, I see Japanese-style rendering. I have not tested this, but I am wondering if it can force the use of the locale , can also force Japanese-style characters to be displayed for devices with 4.1 +.

You cannot set the font to one of the attributes in the XML attribute. You should do this in Java using code similar to what you posted in the original question. To do this globally, you can either make your own TextView subclass that sets the correct font, or you can iterate over all the views in the layout (for example, after Activity.setContentView (int)) and update them accordingly if they are TextViews , Below is a slightly more detailed description of this solution in another question . Including the Japanese font is likely to inflate your APK for a significant amount.

If you are writing an application for Japanese users in Japan, I would not take any action, since it should correctly display them. Users of Android 4.1+ devices also have good experience, provided that they use Japanese. Otherwise, font binding is your answer, and you already have a good idea of ​​what is required.

+5
source

The answer to a very similar question is here:

Android custom font

You can use some code from GitHub https://github.com/browep/AndroidCustomFontWidgets/ to specify the font in XML.

 <com.github.browep.customfonts.view.FontableTextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="This is in a custom font" app:font="MyFont-Bold.otf" /> 
+2
source

Source: https://habr.com/ru/post/1469222/


All Articles