2017-07-10 31 views
0

我正在開發一個應用程序的項目。
我想顯示這個引號:«和»。但它顯示的數字:2131296435和2131296434.如何顯示這種引號«...»?

他們的價值(«和»)是在一個XML文件:

<string name ="open_quote">«</string> 
<string name ="close_quote">»</string> 

,並在我的Java代碼我有這樣的事情:

text.setText(R.string.open_quote+aStringValue+R.string.close_quote); 

回答

4

嘗試使用t他以下幾點:

<string name ="open_quote">\u00ab</string> 
<string name ="close_quote">\u00bb</string> 

你也應該設置文本這樣,因爲每個字符串值保存爲一個整數值到R.java:

text.setText(getString(R.string.open_quote) + "text" + getString(R.string.close_quote)); 

Source

0

您可以使用

text.setText("\u003C\u003C); // for << 

結帳這對於統一碼

https://unicode-table.com/en/#003C

+0

這是一個糟糕的建議。間距不正確,需要兩個字符而不是一個字符,並且不能在文本中搜索引號字符。 – jAC

2

在XML文件中,

嘗試使用HTML實體:&laquo;«&raquo;»
或等效的Unicode字符:\u00ab«\u00bb»

0

感謝你的幫助。

我發現這個錯誤不是來自我的XML文件,但在我的Java代碼

它應該是

getResources().getString(R.string.open_quote) 

代替:

R.string.open_quote 

in xml,兩個作品:

<string name ="open_quote">\u00ab</string> 
<string name ="close_quote">\u00bb</string> 

OR

<string name ="open_quote">«</string> 
<string name ="close_quote">»</string> 

所以,在我的代碼,我有: text.setText(getResources().getString(R.string.open_quote)+aStringValue+getResources().getString(R.string.close_quote));

+1

'getString(R.string.open_quote)'和'getString(R.string.close_quote)'也應該適合你。 – sininen

+0

確實,它也可以 –