问题
How can I change the font on android to allow to show special characters like "'" or "à"? Actually the strings that contains these characters are stored in the sqlite database.
回答1:
When you load the text into your TextView
, will this work for you?
textView.setText(new String(textFromDatabase, "UTF-8"));
This uses the String constructor to set the charset name. You can change "UTF-8" to a different Character encoding -- Also, look at the javadoc for String.
String(byte[] bytes, String charsetName)
- Constructs a new String by decoding the specified array of bytes using the specified charset.
回答2:
The Droid font supports the "'", "à" and many others characters. I use them all the time (pt language).
Actually, I'm quite sure they support all the Basic Latin, Latin 1 supplement and the first extended latin range. They also support many others like hebrew etc., although I'm not sure if that changed between SDK versions.
You can also download the Unicode Map app in the Market to check which characters are available in your particular device. I also store unicode text in sqlite all the time, and still I don't have any problems.
One thing to consider: check that the encoding you are setting match the encoding of your source. It may be a text or a URL... an example:
BufferedReader b = new BufferedReader(new InputStreamReader(url.openStream(), MY_ENCODING));
Are you sure it's not a problem somewhere?
回答3:
You should use ''
instead of '
to store it into Sqlite database.
For example if you want to store 5 o'clock
into database then you have to write this as 5 O''clock
. Take a look here, for more information about it.
回答4:
By default Android SQLite uses UTF-8. I had this problem because when I populated the database on the first launch I used a txt file with another charset.
来源:https://stackoverflow.com/questions/6357789/problem-with-special-characters