Special characters are not displayed on android

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

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

When I use a line through an instruction:

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

the output will be:

test¹, test², test, test

I cannot display special characters: ⁶, ⁷.

Can someone help me solve the problem?

Thanks!

+4
source share
3 answers

I 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 Toast, it really looks like test¹, test², test, test , while the Logcat string is displayed correctly - test¹, test², test⁶, test⁷ - everything is fine, since you are defining your string resource.

I assume that the default font used for the user interface does not provide these characters ( and ). You can try using your own font from assets, making sure that it supports the required characters

+3
source

you can try this

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

Have you added the header to the xml file?

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

If the problem still happens or you need to make sure that everything is displayed correctly. You can save String as utf8 encoded code and parse it after reading it. Similar to what the rotation window builder does if you enter a special character in the Swing GUI window builder.

0
source

Source: https://habr.com/ru/post/1481719/


All Articles