Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Hardcoded <code>String</code> value in <code>View</code> is not recommeded by <a href="http://developer.android.com/guide/topics/resources/string-resource.html" rel="nofollow">developer.android.com</a> as making of Android Application compatible with different languages is twisted up to. </p> <p>Referenced from </p> <p>To add support for more languages, create additional values directories inside res/ that include a hyphen and the ISO country code at the end of the directory name. For example, values-es/ is the directory containing simple resourcess for the Locales with the language code "es". Android loads the appropriate resources according to the locale settings of the device at run time.</p> <p>Once you’ve decided on the languages you will support, create the resource subdirectories and string resource files. For example:</p> <pre><code>MyProject/ res/ values/ strings.xml values-es/ strings.xml values-fr/ strings.xml </code></pre> <p>Add the string values for each locale into the appropriate file.</p> <p>At runtime, the Android system uses the appropriate set of string resources based on the locale currently set for the user's device.</p> <p>For example, the following are some different string resource files for different languages.</p> <p>English (default locale), /values/strings.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;resources&gt; &lt;string name="title"&gt;My Application&lt;/string&gt; &lt;string name="hello_world"&gt;Hello World!&lt;/string&gt; &lt;/resources&gt; </code></pre> <p>Spanish, /values-es/strings.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;resources&gt; &lt;string name="title"&gt;Mi Aplicación&lt;/string&gt; &lt;string name="hello_world"&gt;Hola Mundo!&lt;/string&gt; &lt;/resources&gt; </code></pre> <p>Referring to your OP:</p> <p>XML file saved at res/values/strings.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;resources&gt; &lt;string name="press"&gt;Press Button&lt;/string&gt; &lt;/resources&gt; </code></pre> <p>This layout XML applies a string to a View:</p> <pre><code>&lt;TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/press" android:textSize="45dp" &lt;!--Warning --&gt; android:layout_gravity="center" android:gravity="center" android:id="@+id/tvDisplay" /&gt; </code></pre> <p>This application code retrieves a string:</p> <pre><code>String string = getString(R.string.hello); </code></pre> <hr> <p>Use <kbd>sp</kbd> for setting <code>size</code> as suggested by <a href="http://developer.android.com/guide/topics/resources/more-resources.html" rel="nofollow">developer.android.com</a></p> <p><code>sp : Scale-independent Pixels - This is like the dp unit, but it is also scaled by the user's font size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and the user's preference.</code></p> <p>XML file saved at res/values/dimens.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;resources&gt; &lt;dimen name="font_size"&gt;16sp&lt;/dimen&gt; &lt;/resources&gt; </code></pre> <p>This application code retrieves a dimension</p> <pre><code>Resources res = getResources(); float fontSize = res.getDimension(R.dimen.font_size); </code></pre> <p>This layout XML applies dimensions to attributes:</p> <pre><code>&lt;TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Press Button" &lt;!--Warning --&gt; android:textSize="@dimen/font_size" android:layout_gravity="center" android:gravity="center" android:id="@+id/tvDisplay" /&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload