Contains one or more elements.Īttributes: name String. A collection of strings, of which, one string is provided depending on the amount of As such, you can combine plurals resources with other simple resources in the one Referenced using the value provided in the name attribute (not the name of the XMLįile). Note: A plurals collection is a simple resource that is This makes your life and your translators' lives easier, if it's an acceptable style for your application. It's often possible to avoid quantity strings by using quantity-neutral formulations such as Rely on your translator to know what distinctions The quantity 2: a language may require that 2, 12, 102 (and so on) are all treated like oneĪnother but differently to other quantities. Conversely, in Korean only the other string isĭon't be misled either by the fact that, say, two sounds like it could only apply to Isn't grammatically different from 2, or any other number except 1 ("zero books", "one book", In English, a string for zero is ignored even if the quantity is 0, because 0 The selection of which string to use is made solely based on grammatical necessity. It might seem convenient to use quantity strings instead of an if statement,īut it's important to note that some languages (such as Chinese) don't make these grammaticalĭistinctions at all, so you'll always get the other string. Implement something like Gmail's "Inbox" versus "Inbox (12)" when there are unread messages, forĮxample. It would be a mistake to use quantity strings to
So Android provides you with methods such asĪlthough historically called "quantity strings" (and still called that in API), quantity The rules for deciding which case to use for a given language and quantity can be very complex,
The full set supported by Android is zero, This distinction between singular and plural is very common, but other We write "1 book", but for any other quantity we'd In English,įor example, the quantity 1 is a special case.
getStringArray(R.anets_array) ĭifferent languages have different rules for grammatical agreement with quantity.
This application code retrieves a string array: example: XML file saved at res/values/strings.xml: Information about to properly style and format your strings.
A string, which can include styling tags. In XML: package:]array/ string_array_name syntax: compiled resource datatype: Resource pointer to an array of Strings. Such, you can combine string array resources with other simple resources in the one XML file, Using the value provided in the name attribute (not the name of the XML file). Note: A string array is a simple resource that is referenced String arrayĪn array of strings that can be referenced from the application. getText(int) retains any rich text styling applied to the string. String string = getString(R.string.hello) Val string: String = getString(R.string.hello) This application code retrieves a string: This layout XML applies a string to a View:
For more information about how to properly style and format your strings see Formatting and Styling, below.Īttributes: name String. Beware that you must escape apostrophes and compiled resource datatype: Resource pointer to a String. So, you canĬombine string resources with other simple resources in the one XML file, Note: A string is a simple resource that is referenced StringĪ single string that can be referenced from the application or from other resource files (such Information about styling and formatting strings, see the section about Formatting and Styling. Quantity Strings (Plurals) XML resource that carries different strings for pluralization.Īll strings are capable of applying some styling markup and formatting arguments. String Array XML resource that provides an array of strings. Your application with strings: String XML resource that provides a single string. There are three types of resources that can provide With optional text styling and formatting. A string resource provides text strings for your application