简体   繁体   中英

Special characters are not displayed in android

I have an xml file containing words with special characters. For example:

<string name="test_text">"test¹, test², test⁶, test⁷ "</string>

When I use the string via the instruction:

((TextView) view.finViewdById(R.id.test)).setText(R.string.test_text);

the output will be:

test¹, test², test, test

I can not display the special characters:⁶, ⁷.

Can someone help me fix the problem?

Thank you!

I've just tested it using two options:

Log.d("TEST", getString(R.string.test_text));
Toast.makeText(this, getString(R.string.test_text), Toast.LENGTH_LONG).show();

In the Toast it indeed appears as test¹, test², test, test , while in Logcat string appears correctly - test¹, test², test⁶, test⁷ - so it looks like everything is fine with the way you define your string resource.

My guess is that default font, used for UI, does not provide these characters ( and ). You can try using your own font from assets, making sure it has support for the required characters

你可以试试这个

((TextView) findViewById(R.id.test)).setText(getString(R.string.test_text, "UTF-8"));

Did you add the header on the xml file?

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

If the problem is still happen or you need to ensure everything show correctly. You can save the String as a utf8 encoded code and parse it after read it out. Like what swing window builder do if you entering special character in Swing GUI window builder.

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.

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