Search code examples
androidlocale

Bug in changing resources after changing locale


I wrote a little app, which has some locales and language options. When user changes the locale, OptionsActivity restarting and updating configuration. MainActivity updating configuration too in onRestart() method. All is well, but if user tap options hardware button, options menu creating with first loaded localized resources. I create options menu with code:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    Log.d(Const.LOG_TAG, "onCreateOptionsMenu");
    final MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.activity_main, menu);
    return true;
}

/menu/activity_main.xml:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:id="@+id/menu_settings"
        android:icon="@drawable/setting_icon"
        android:title="@string/menu_settings"/>
</menu>

menu_setting is localized string. What is wrong? Why are some resources updating, but some resources are not?


Solution

  • I've got it.

    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        Log.d(Const.LOG_TAG, "Menu prepared");
        MenuItem item = menu.findItem(R.id.menu_settings);
        item.setTitle(R.string.menu_settings);
        return true;
    }