i was trying to localize my app with different languages everything works but the items on the drawer layout wont update to the new language unless the app is restarted heres the code i used to change the language.
Locale locale = new Locale(lang);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
c.getResources().updateConfiguration(config,c.getResources().getDisplayMetrics());
the variable lang being the language thats being set.
so is there any way i can refresh the drawer layout after the language is set?
Related
As Google-Map App in our phone shows the different languages as per region with English.
I want to implement same in my app also.
But i can not do this in android.
can you please help me to get out of it.
Set Google Map language as Locale language
https://developers.google.com/maps/documentation/javascript/basics?csw=1#Localization
https://developers.google.com/maps/documentation/javascript/localization
Please check this link What is the list of supported languages/locales on Android? for supported language.
&
you can do this by simply changing the Locale of your application like this in your Splash or where you loading the maps.
String languageToLoad = "ar";
Locale locale = new Locale(languageToLoad);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
Hope this may help you.
Is there a way to force using english as the locale for my android app even if the phone's locale is something other that english? The reason I want to do this is that I don't want my UI to change orientatoin from ltr to rtl.
this line
mStrLocale = Locale.getDefault().getLanguage();
will return your current language, lets say EN-US
and with this you can hardcode your locale
Locale locale = new Locale("ru");
Locale.setDefault(locale);
Configuration config = getBaseContext().getResources().getConfiguration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
and we use Configuration because of this
This class describes all device configuration information that can
impact the resources the application retrieves. This includes both
user-specified configuration options (locale list and scaling) as well
as device configurations (such as input modes, screen size and screen
orientation).
is stated at this doc https://developer.android.com/reference/android/content/res/Configuration.html
I am developing an app with english and french language support.
If user change language , textview texts are changed.
But images in ImageView does not change.
If user selects language=='fr' image should be displayed from drawable-fr.
How to achieve this?
I am changing locale like:
Locale myLocale = new Locale(language);
// set the new locale
Locale.setDefault(myLocale);
Configuration config = new Configuration();
config.locale = myLocale;
getApplicationContext().getResources().updateConfiguration(config,
getApplicationContext().getResources().getDisplayMetrics());
I solved problem.
As user changes language,i was resetting image like iv.setImageResouse(R.drawable.asdf); in onRestart() method of previous activity.
But then i replaced this with iv.setImageDrawable(getResources().getDrawable(R.drawable.asdf));
This worked.
I want to convert my android project to multiple language. I have created a list view where different languages are going to be shown. I want to change the device language when I select any item from this list. How can I do this?
You can change the the Language like this
Locale locale = new Locale("en_US");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
context.getApplicationContext().getResources().updateConfiguration(config, null);
I have the following EditText:
EditText et1 = (EditText) findViewById(R.id.txtSp);
When user types in this EditText, it should display text in Spanish instead of English.
How can I achieve this?
Note: My application's language is English.
You can change the locale at runtime using that code:
Resources res = getApplicationContext().getResources();
Locale locale = new Locale("en"); //<--- use your locale code here
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
res.updateConfiguration(config, res.getDisplayMetrics());
I assume you need to reset your layout afterwards too.
According to this post, it is not possible to change the locale for a currently running app.
Google Groups -> Android Developers
The "DH" that Richard mentions in this post is an Android Framework Engineer. Look at Richard's previous post for a link to her comments.