更改片段活动android中的本地化

时间:2012-05-25 11:41:02

标签: android localization

我尝试在应用中更改应用本地化。我试图改变动作栏子meniu:

    @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);
}

我忘记了什么?

由于

0 个答案:

没有答案