【android】strings.xml中要注意的一個小問題和使用strings.xml中的資源時要注意的小問題



<span style="font-size:18px;"><string name="info">info</string>
<string name="restart">Start a New Game</string>
<string name="android_turn">"It's Android's turn."</string>
<string name="human_turn">"It's your turn (X)."</string>
<string name="tie">"It's a tie!"</string></span>

當string中包含單引號時,需要將string用雙引號包括起來,否則會報錯


<span style="font-size:18px;">computer_count++;
mHumanCount.setText(getString(R.string.human_win_count)+ " : " + human_count);
mComputerCount.setText(getString(R.string.computer_win_count)+ " : " + computer_count);</span>


對一個textview使用settext方法,當想要用strings.xml中的資源時,要加getString(),否則R.string.STRING_ID返回的是一串數字

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章