4

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.

jagmohan
  • 2,052
  • 2
  • 26
  • 41

4 Answers4

16


[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);
Joel Fernandes
  • 4,776
  • 2
  • 26
  • 48
  • What's difference between "\u20B9" and "₹"? Can you please explain? – jagmohan Nov 24 '13 at 14:57
  • No difference. Works the same. I thought the alternative might work. – Joel Fernandes Nov 24 '13 at 15:08
  • I am testing on emulator running 2.2. Tested what you suggested but didn't work. And on emulators for 4.2, 4.3, etc, what I have is working. – jagmohan Nov 24 '13 at 15:09
  • @singh.jagmohan Please check my edit. I've edited my answer with a working solution. Hope it helps. Cheers! – Joel Fernandes Nov 24 '13 at 15:42
  • try using RupeeTextView https://gist.github.com/john1jan/a82912fb355771e565bea1720439c5dc . It prefixes rupee symbol and adds even give comma separated amount – John Jul 08 '16 at 07:03
3
<string name="current_amount">Balance: &#x20B9;</string>

I have tried this and it works

0

You need to ensure you are using a font that can display this unicode character. You can change the font of your views as follows:

In your main activity MainActivity.java

public static final String PREF_MYFONT = "DejaVuSansCondensed.ttf";

In your view where you need to display the Rupee symbol MyView.java

@Override
public void onStart() {
    super.onStart();

    myTitle=(TextView) getActivity().findViewById(R.id.title);
    myDescription=(TextView) getActivity().findViewById(R.id.description);

    Typeface font = Typeface.createFromAsset(getActivity().getAssets(), MainActivity.PREF_MYFONT);  

    myTitle.setTypeface(font);
    myDescription.setTypeface(font);
}
ceyquem
  • 2,079
  • 1
  • 18
  • 39
0

pendingApprovalReceiptPaymentFragmentBinding.tvAmountValue.setText(getResources().getString(R.string.Rs)+" "+Integer.toString(pendingApprovalListModel.getAmount()));

Soumen Das
  • 1,292
  • 17
  • 12