1

我尝试在应用程序中更改应用程序本地化。我尝试从操作栏子菜单更改:

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
SubMenu langSelection = menu.addSubMenu(getString(R.string.message_lang));

            langSelection.add(getString(R.string.message_eng)).setOnMenuItemClickListener(new
                    OnMenuItemClickListener()
            {

                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        // TODO Auto-generated method stub
                        System.out.println("ENG");
                        try{

                            String languageToLoad  = "en";  
                            Locale locale = new Locale(languageToLoad);   
                            Locale.setDefault(locale);  
                            Configuration config = new Configuration();  
                            config.locale = locale;  
                            //getBaseContext().getResources().updateConfiguration(config,   
                           // getBaseContext().getResources().getDisplayMetrics());  

                            mContext.getApplicationContext().getResources()
                            .updateConfiguration(config, null);


                        }catch (Exception e) {
                            // TODO: handle exception
                            e.printStackTrace();
                        }


                        return true;
                    }

            });
            MenuItem subMenu1Item = langSelection.getItem();
            //setting pic for Actions
           // subMenu1Item.setIcon(R.drawable.icon57);
            subMenu1Item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

        }

        return super.onCreateOptionsMenu(menu);
    }

这段代码在 FragmentActivity 中。在 minifest 中,我添加了:

android:configChanges="locale"

但是当我改变 lang 时,这不会被调用:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    // TODO Auto-generated method stub
    System.out.println("onConfigurationChanged() Called");
    super.onConfigurationChanged(newConfig);
}

我忘记了什么?

谢谢

4

0 回答 0