The content of string.xml files:
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">DemoMultipleLanguages</string> <string name="hello_world">Hello world!</string> <string name="action_settings">Settings</string> </resources>
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">Demostración Múltiples idiomas</string> <string name="hello_world">¡Hola, mundo </string> </resources>
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">Demo plusieurs langues</string> <string name="hello_world">Bonjour tout le monde </string> </resources>
P/S: I used Google Translate for Spanish and French so please don’t mind if there’re any rediculous mistakes about translations.
It’s super easy to get the String resource value:
// Get a string resource from your app's Resources String hello = getResources().getString(R.string.hello_world); // Or supply a string resource to a method that requires a string TextView textView = new TextView(this); textView.setText(R.string.hello_world);
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="ice.tea09.demomultiplelanguages.MainActivity$PlaceholderFragment" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> </RelativeLayout>
And the result for this demo:
https://drive.google.com/file/d/0Bw3dwdSezn6fNGVoVDh0dXNORFE/edit?usp=sharing
Comments powered by Disqus.