在文本视图中显示日语而不是中文 [英] Displaying japanese instead of chinese in a textview

查看:123
本文介绍了在文本视图中显示日语而不是中文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当在文本视图中显示日文文本时,Android默认使用中文字体,显示错误的字符,例如

When displaying japanese text in a textview, android defaults to using a chinese font, showing the wrong characters, exemplified here. Setting the locale to japanese works on the emulator, but doesn't work on my galaxy s3, probably because it doesn't support Japanese. There other solution is to set the font programattically from an asset such as:

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

但这似乎有点不合时宜.有没有办法通过xml布局将字体设置为支持日语的字体?

but that seems like a bit of a kludge. Is there any way to set the font through the xml layout to one that supports japanese?

推荐答案

无法直接在XML中设置字体.

There's no way to set the font directly in XML.

如果您打算使用很多日语TextView,则创建一个自定义View来为您处理它可能会更容易,该View通过其构造函数以编程方式设置字体.

If you plan on using a lot of Japanese TextViews, it may be easier to create a custom View to handle it for you, which sets the font programmatically from its constructor(s).

那么,只要您以XML放下自定义视图,它就会具有正确的字体.

Then any time you plop your custom View down in XML, it'll have the correct font.

这篇关于在文本视图中显示日语而不是中文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆