Other usage of strings. xml in Android
Usage 1: normal string
text_string
Usage 2: string Array
text_string
Java code:
Resources res = getResources();String[] planets = res.getStringArray(R.array.planets_array);
Usage 3: Plurals
One song found.
%d songs found.
Java code:
int count = getNumberOfsongsAvailable();Resources res = getResources();String songsFound = res.getQuantityString(R.plurals.numberOfSongsAvailable, count);
Usage 4: Formatting and Styling Formatting, placeholder, etc.
1. format the string
Hello, % 1 $ s! You have % 2 $ d new messages.
// Java code Resources res = getResources (); String text = String. format (res. getString (R. string. welcome_messages), username, mailCount );
2. html
Welcome to
Android!
3. Combination of the above two methods
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);