I add a rating to a TextView
programmatically by setting some unicode stars. It's the unicode star \⋆ , but the TextView
shows me this character when I start the app: \⊠ .
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.
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:
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. Do something like this
mTextView.setText(Html.fromHtml(text));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.