Hello there.
I want to help me . I am a beginner in programming android Studio.
I want to pass a "specific picture" in Android Studio, According to the default language of the phone.
Example: I have two pictures, picture 1: it has Arabic writing. Picture 2: It has English writting .
Q . I want to use the conditionals "if" and "else if" in the statement?
EX : if(the language is Arabic){pass the picture 1 } else if(the language is English){pass the picture 2 }…..and so on to multiple languages.
- Please, I want an answer to this algorithm.
2
Answers
There are 2 ways to do this:
First way, using
switch
andcase
( more efficient ):Second way, using
if else
( less efficient ):In both ways,
yourImageViewID
is anImageView
, Don’t forget to add 3 images to your assets, one for the Arabic language, another one for the English language, and a third one for other languages ( will be used if device language isn’t Arabic or English ), also add more images if you want to add more languages to your applicationYou can do this by adding each picture to a different locale version within
resdrawable
. Both versions of pictures must have the same name in order to allow Android system to pick the appropriate picture when checking the device language.In your example your locales are English & Arabic, so you need to have two folders:
appsrcmainresdrawable-armyPicture.png
<< Arabic versionappsrcmainresdrawable-enmyPicture.png
<<< English versionBoth pictures have the same name but they are different in content as you need.