How to make the Java code to call a String from a XML file(In Android Studio)
20,823
Solution 1
Put getString(R.string.welcome)
instead of "WELCOME".
Solution 2
You have to use it like this:
getApplicationContext().getResources().getString(R.string.YOURSTRING);
Depending where in code, a simple
getString(R.string,ID);
could be enough.
Solution 3
In the res/values folder there is a file called strings.xml put there the String
Example
<string name="welcome">Welcome</string>
and change the Toast to
Toast.makeText(getApplicationContext(),R.string.welcome, Toast.LENGTH_LONG).show();
now if you want to add more languages create libraries in the res folder named according to the language : values-fr/ and place inside strings.xml
Android Multi Language Tutorial
Author by
App The Android
Updated on May 15, 2020Comments
-
App The Android almost 4 years
I have this code and I will like to make it multi language app. What I want is to use the Strings from the Strings.xml file under the directory of values.
Let's say I have a
Toast
...Toast.makeText(getApplicationContext(), "WELCOME", Toast.LENGTH_LONG).show();
But I don't want to put the welcome in the java but to get it from the xml file, but How?