2012-12-07 59 views
0

耳目一新的應用程序我是迫使選項更改後的語言環境:強制語言環境和新的語言

public void forceLocale(Context ctx) { 
    Locale.setDefault(getCurrentLocale()); 
    Configuration config = new Configuration(); 
    config.locale = getCurrentLocale(); 
    ctx.getResources().updateConfiguration(config, ctx.getResources().getDisplayMetrics()); 
} 

我想顯示在一個新的語言環境的當前活動,但它doesen't發生。其他活動也是如此。

我想對我的所有活動的onResume()無效:

protected void onResume() { 
    //if no custom locale, restore default 
    if (StaticClass.locale.getCurrentLocale() == null) 
     StaticClass.locale.restoreDefaultLocale(); 

    //force curretnt locale 
    StaticClass.locale.forceLocale(this); 

    //reload the view 
    ViewGroup vg = (ViewGroup) findViewById(android.R.id.content); 
    vg.invalidate(); 

    super.onResume(); 
} 

無影響。應用程序在從內存中清除並重新啓動後會被翻譯

回答

0

您是否在清單中設置了語言環境屬性android:configChanges="locale"?我在每個活動也添加到了我的onCreate()

if (Globals.langConfig != null) this.onConfigurationChanged(Globals.langConfig);

然後我在每個活動

@Override 
     public void onConfigurationChanged(Configuration newConfig) { 
     newConfig = Globals.getUserLanguage(this); 

super.onConfigurationChanged(newConfig); 

這可能不是最好的辦法,但現在已經爲我工作覆蓋。如果你還沒有,我認爲重寫方法可能是你最大的問題