简体   繁体   English

Android TextView没有显示正确的字符

[英]Android textview doesn't show correct characters

So I have an object that contains a couple of strings. 所以我有一个包含几个字符串的对象。 the text in this string sometimes contains special characters like ë,ô, é, etc... 该字符串中的文本有时包含特殊字符,例如ë,ô,é等。

Now when I set the text in my TextView to show what is inside the string it does show the text but replaces all the special characters with ? 现在,当我在TextView中设置文本以显示字符串中的内容时,它的确显示了文本,但是将所有特殊字符替换为?

Any ideas how to fix this? 任何想法如何解决这一问题?

Note the textView is used as an listitem for a listview, and the data is extracted from a .csv file. 请注意,textView用作列表视图的列表项,并且数据是从.csv文件中提取的。

<?xml version="1.0" encoding="utf-8"?>

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#DBBD59"
android:textColor="#666666"
android:gravity="center"
android:textSize="10pt">

</TextView>

These are latin fonts which are not supported for your device. 这些是您的设备不支持的拉丁字体。
So use custom latinfont ttf to show these font. 因此,请使用自定义latinfont ttf显示这些字体。

TextView textView = (TextView) rowView.findViewById(R.id.yourtextviewfromXml);
Typeface font = Typeface.createFromAsset(getContext().getAssets(), "latin_font_ttf_file.TTF");
textView.setText("ë,ô, é");
textView.setTypeface(font);

Note: save ttf file in assets folder. 注意:将ttf文件保存在资产文件夹中。
This post may help you How to display Latin-1 characters in Android app 这篇文章可能会帮助您如何在Android应用中显示Latin-1字符

try to replace your special characters with their unicode. 尝试用其unicode替换您的特殊字符。

for example replace é with &\\#223 例如,将é替换为&\\#223

See this http://www.codetable.net/unicodecharacters for more information 有关更多信息,请参见此http://www.codetable.net/unicode字符

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM