C
C
Chvalov2015-08-27 22:08:49
Android
Chvalov, 2015-08-27 22:08:49

Is it possible to use strings from values/strings.xml (Android) in code?

For example, is it possible here:

Toast.makeText(getApplicationContext(), "TEXT-TEXT-TEXT", Toast.LENGTH_LONG).show();

Instead of TEXT-TEXT-TEXT, take text from values/strings.xml so that when creating multilingual applications, Toast produces text in the desired language ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Bolshakov, 2015-08-27
@Chvalov

Something like that:
Or call getString() right away, but it depends on where to call the method:

Toast.makeText(getApplicationContext(), getString(R.string.your_text), Toast.LENGTH_LONG).show();

K
kirich1409, 2015-08-28
@kirich1409

Toast has an overload of the makeText() method that immediately takes the id of a string resource as input

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question