0

我为语言选择创建了菜单。我正在通过 JSON 收集数据,所以这是运行时的。现在我需要更改内容或数据的语言,所以我正在使用这段代码。但它不起作用。

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

请高手帮帮我。还有其他方法可以转换为语言吗?或任何图书馆?

4

1 回答 1

0
    I think method you are using is correct. please check your language code.
    protected void language(String languageToLoad) {
            // TODO Auto-generated method stub
            Locale locale = new Locale(languageToLoad);   
            Locale.setDefault(locale); 
            Configuration config = new Configuration();  
            config.locale = locale;  
            getBaseContext().getResources().updateConfiguration(config,   
            getBaseContext().getResources().getDisplayMetrics());  
        }

   Be sure that strings file are exists in folder name appending by same language code.
于 2013-09-23T11:19:22.923 回答