[英]Android: TextView, unicode character not shown properly
I add a rating to a TextView
programmatically by setting some unicode stars. 我通过设置一些unicode星标以编程方式向
TextView
添加了评级。 It's the unicode star \⋆ , but the TextView
shows me this character when I start the app: \⊠ . 它是unicode星号\\ u22C6 ,但是启动应用程序时,
TextView
向我显示此字符: \\ u22A0 。
This is how I created it: 这是我创建它的方式:
private CharSequence calculatedSelectedRating(Integer rating)
{
StringBuffer stringBuffer = new StringBuffer();
//Star is ⋆ or \u22C6
for (int i = 0; i < rating; i++)
{
stringBuffer.append('\u22C6');
}
return stringBuffer.toString();
}
and the result is what I set in TextView
by setText(...)
method. 结果是我通过
setText(...)
方法在TextView
设置的。
Any ideas why this discrepancy occurs? 任何想法为什么会出现这种差异?
Some fonts don't support some characters. 某些字体不支持某些字符。 Check your message is shown with other font;
检查您的消息是否以其他字体显示; include the ttf file on your assets folder, and set the content of the TextView with that font with something like:
在您的资产文件夹中包含ttf文件,并使用该字体将TextView的内容设置为类似以下内容:
yourTextView=(TextView)findViewById(R.id.idOfYourTextView);
Typeface font= Typeface.createFromAsset(getAssets(), "The_Font.TTF");
yourTextView.setTypeface(font);
Hope it helps. 希望能帮助到你。
尝试使用"
代替'
stringBuffer.append("\u22C6");
On your TextView, you can use HTML format to set the text. 在TextView上,可以使用HTML格式设置文本。 Do something like this
做这样的事情
mTextView.setText(Html.fromHtml(text));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.