This is the first time I do that .I want to make a language selection in my app contains Arabic
and English
. I have a problem , When user change the language of the app , It doesn't change the texts it change the layout direction only .I have 2 String
file . The original for English
and the other string-ar
for Arabic
I searched and tried many solution .
One of them is in this article
And here is my code .
public void setLocaleAr (){
Locale locale = new Locale("ar");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
Resources resources = getResources();
resources.updateConfiguration(config, resources.getDisplayMetrics()); //deprecated
}
Edit : when I use my code . The texts in my Spinner
changed . but the text which is in the xml
file didn't change .
I used example from this article in many projects and it works great.
As it says in the article you need to update the text or any other language dependent resources one by one. Or you can call activity.recreate() to restart currently loaded activity. Then the activity will reload the resources with the correct locale. However, if you select this option your users will notice the affect because it will close your application and you get black screen for a very small amount of time and then recreate your activity again in meanwhile.