0

I defined layouts for multiple languages and multiple devices like below:

enter image description here

I set proper layout with custom language like bellow :

String languageToLoad = "ar"; 
Locale locale = new Locale(languageToLoad);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.setLocale(locale);
getBaseContext().getResources().updateConfiguration(config, null);
this.setContentView(R.layout.activity_main);

For language (ar - Arabic) I fetch layout-ldrtl or layout-ldrtl-sw600dp and other language (en - English) I fetch layout-ldltr or layout-ldltr-sw600dp and above code good work.

Problem : In this line getBaseContext().getResources().updateConfiguration(config, null); say me updateConfiguration is deprecated and then I use from createConfigurationContext but when I use from this method the source don't work true and don't get me proper layout .

1 Answers1

0

Resolved my problem. I use from this LINK then in my activity use from bellow code :

Context context = MyContextWrapper.wrap(this, "en");
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(context.getResources().getLayout(R.layout.activity_main), null);
this.setContentView(view);