關於Android中的strings.xml的一些其他用法
用法1:普通string
text_string
用法2:string 數組
text_string
java代碼中使用:
Resources res = getResources();String[] planets = res.getStringArray(R.array.planets_array);
用法3:Plurals
One song found. %d songs found.
java代碼:
int count = getNumberOfsongsAvailable();Resources res = getResources();String songsFound = res.getQuantityString(R.plurals.numberOfSongsAvailable, count);
用法4:Formatting and Styling 格式化、佔位等
1.格式化字串
Hello, %1$s! You have %2$d new messages.//java代碼Resources res = getResources();String text = String.format(res.getString(R.string.welcome_messages), username, mailCount);
2.html
Welcome to Android!
3.以上兩種方式的結合體
Hello, %1$s! You have <b>%2$d new messages</b>.Resources res = getResources();String text = String.format(res.getString(R.string.welcome_messages), username, mailCount);CharSequence styledText = Html.fromHtml(text);