簡體   English   中英

Android:TextView,unicode字符無法正確顯示

[英]Android: TextView, unicode character not shown properly

我通過設置一些unicode星標以編程方式向TextView添加了評級。 它是unicode星號\\ u22C6 ,但是啟動應用程序時, TextView向我顯示此字符: \\ u22A0

這是我創建它的方式:

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();
}

結果是我通過setText(...)方法在TextView設置的。

任何想法為什么會出現這種差異?

某些字體不支持某些字符。 檢查您的消息是否以其他字體顯示; 在您的資產文件夾中包含ttf文件,並使用該字體將TextView的內容設置為類似以下內容:

yourTextView=(TextView)findViewById(R.id.idOfYourTextView);
Typeface font= Typeface.createFromAsset(getAssets(), "The_Font.TTF");
yourTextView.setTypeface(font);

希望能幫助到你。

嘗試使用"代替'

stringBuffer.append("\u22C6");

在TextView上,可以使用HTML格式設置文本。 做這樣的事情

mTextView.setText(Html.fromHtml(text));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM