2013-11-24 40 views
4

我在strings.xml文件中使用以下字符串條目來顯示盧比符號。通過字符串xml顯示盧比符號不起作用

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

它在Android 2.2上顯示一個正方形而不是實際的符號。

請幫忙。

PS:我在Android 2.2的模擬器上測試它,我沒有2.2設備。

+0

試試這個你有沒有安裝包含符號的字體?模擬器設置的區域設置是什麼? – Simon

+0

我還沒有安裝字體。語言環境設置爲美國。 – jagmohan

+0

對不起,我已經安裝了Roboto_Light.ttf字體,並有自定義文本視圖在我的應用程序中顯示文本。 – jagmohan

回答

14


[編輯]適用於Android 2.2的靈魂工作

好吧,這是你如何才能使它工作。您必須從here下載字體Rupee_Foradian.ttf,並將其放在assets文件夾中。

然後,把此行strings.xml文件

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

最後使用此代碼設置字體:

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


[原創]在Android 2.2

把這一行在strings.xml文件

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

在您的代碼不工作,例如,如果你將其分配給TextView中做到這一點:

TextView text = (TextView) findViewById(R.id.text); 
text.setText("Balance " + getResources().getString(R.string.rs) + VALUE); 
+0

「\ u20B9」和「&#x20B9;」有什麼區別?你能解釋一下嗎? – jagmohan

+0

沒有區別。工作原理相同。我認爲替代方案可能會起作用。 – JoelFernandes

+0

我在運行2.2的模擬器上測試。測試了你的建議,但沒有奏效。而在4.2,4.3等仿真器上,我所擁有的就是工作。 – jagmohan

0

您需要確保您使用的字體可以顯示此Unicode字符。 如下您可以更改您的視圖的字體:

在您的主要活動MainActivity.java

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

在你看來,你需要顯示的盧比符號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); 
} 
1
<string name="current_amount">Balance: &#x20B9;</string> 

我已經嘗試這樣做,它的工作原理

0

字符串中

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

(or) 

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