2015-11-16 45 views
0

我的Android應用程序有它自己的語言,它可能與設備系統語言不相同。對於前 - MyApp有'ru'語言,但手機有'en'lang。 我可以做應用程序來使我的應用程序語言的語言環境資源,而不是系統語言? -從應用程序語言(而不是系統語言)中選擇資源

PS我的應用我通過這段代碼改變語言:

public static void setLocale(String language) { 
     Locale locale = new Locale(language); 
     Locale.setDefault(locale); 
     Configuration config = new Configuration(); 
     config.locale = locale; 
     SvoApplication.getContext().getResources().updateConfiguration(config, 
                     SvoApplication.getContext() 
                        .getResources() 
                        .getDisplayMetrics()); 
     SharedPreferencesManager.setCurrentLanguage(language); 
    } 

而且已經從數據庫中採取的所有數據由應用語言

PPS的sharedPref價值定位 - 我知道我必須使用strings-en.xml/strings-ru.xml等等。當我改變我的應用程序lang時它就起作用了。但是,當我如旋轉屏幕 - 所有的資源都改變什麼系統默認語言是

+0

看看[官方文檔](http://developer.android.com/intl/es/guide/topics/resources/localization.html) –

回答

0

你可以重寫在類延伸Application.class onConfigurationChanged方法。並設置config.locale同上

public void onConfigurationChanged(Configuration config) { 
    super.onConfigurationChanged(config); 
     /*here code to set locale*/ 
} 

,現在它會正常工作,當你旋轉屏幕。

+0

我會測試它並寫下關於結果的信息! thnks! –

+0

是的,它的工作!謝謝! –