3

I am developing an app that uses text in 3 languages. English, Kurdish and Arabic. I am trying to change the layouts dynamically when user changes language. I have a settings screen where the user can change language that is I am not changing language from the system settings but from within my app. For example the layout should change from RTL to LTR if I switch from Kurdish to English or vice versa. I tried to use onConfiguterionchanged() but it is not getting triggered.

Changing locale: Force activity to reload resources? had the answer to the question.

I tried

  1. Android: locale(system Language) change effect my application layouts.

  2. Android Localization problem: Not all items in the layout update properly when switching locales,

  3. Trying to change Android Locale on the fly.

  4. http://www.c-sharpcorner.com/UploadFile/1e5156/how-to-change-locale-of-an-application-dynamically-in-androi/

without success.

I tried onResume() which gets triggered but the layout is not changed when the language is changed. I use the following code to change the locale. LocaleSingleton is a class that I created to hold an instance of Configuration.

@Override
    protected void onResume() {
        getResources().updateConfiguration(LocaleSingleton.getInstance().getConfig(), getResources().getDisplayMetrics());
        AsyncData data = new AsyncData();
        data.execute(String.valueOf(id), Constants.SERVER + "ad_detail.php");

        super.onResume();
    }

Any help is appreciated. Thanks in advance. Edit: I have also tried to restart the activity in onResume() but I get only a black screen. Thanks again.

Community
  • 1
  • 1
Pankaj Agarwal
  • 117
  • 1
  • 16

1 Answers1

0

Add this to your activity in your manifest

<activity
            android:name=".YourActivity"
            android:configChanges="orientation|keyboardHidden|screenSize" >
        </activity>
Barışcan Kayaoğlu
  • 1,294
  • 3
  • 14
  • 35
  • Basically, orientation force your activity to go onConfigurationChanged() when you change your orientation and after 4.0 screenSize is also required for it. I'm not sure but I'm guessing keyboardHidden force your keyboard to dismiss when you change the orientation. – Barışcan Kayaoğlu May 13 '14 at 10:57
  • Didn't work? That's the configuration that all android devices use. If it's not working you probably deactivated your orientation change from your device settings on your device. – Barışcan Kayaoğlu May 15 '14 at 07:45