Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display rupee symbol via strings xml not working

I using the following string entry in strings.xml file to display rupee symbol.

<string name="current_amount">"Balance: &#x20B9;%.2f"</string>

It displays a square rather than the actual symbol on Android 2.2.

Please help.

PS: I am testing it on an emulator for Android 2.2, I don't have a 2.2 device.

like image 810
jagmohan Avatar asked Dec 01 '22 17:12

jagmohan


2 Answers


[EDIT] Working soultion for Android 2.2

Ok here's how you can get it to work. You'll have to download the font Rupee_Foradian.ttf from here and put it in the assets folder.

Then, place this line in strings.xml file

<string name="rs">`</string>

And finally set the Typeface using this code:

TextView t = (TextView) findViewById(R.id.text);
Typeface face = Typeface.createFromAsset(getAssets(), "Rupee_Foradian.ttf");
t.setTypeface(face);
t.setText("Balance " + getResources().getString(R.string.rs));



enter image description here


[Original] Doesn't work on Android 2.2

Put this line in your strings.xml file

<string name="rs">\u20B9</string>

In your code, for example, if you're assigning it to a TextView do this:

TextView text = (TextView) findViewById(R.id.text);
text.setText("Balance " + getResources().getString(R.string.rs) + VALUE);
like image 129
Joel Fernandes Avatar answered Dec 10 '22 11:12

Joel Fernandes


<string name="current_amount">Balance: &#x20B9;</string>

I have tried this and it works

like image 32
Clemence Ayekple Avatar answered Dec 10 '22 13:12

Clemence Ayekple