本文介绍了Android的用户设置的语言环境总要得到的onCreate后重置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有一个可配置的语言设置我的应用程序。

所以,我活动的onCreate,我叫Resources.updateConfiguration用新的语言环境。

不过,之后的onCreate(在某些时候,我找不到它的时候),在区域设置回默认的语言环境。

在低于$ C $℃实施例,在主要布局所示的串(如由充气的setContentView)示出了在语言的版本,但是当我preSS的菜单按钮,在其上onCreateMenu被调用时,琴弦是从恩(默认值)区域设置拍摄。

日志显示如下:

  18337的OnCreateð{规模= 1.0 IMSI =一分之五百二十五LOC =的InTouch = 3键= 1/1/2 NAV = 3/1广州澳凌= 1布局= 34 uiMode = 17 SEQ = 143}
 30430 ActivityManager我显示活动yuku.coba.locale / .CobaLocaleActivity:266毫秒(总266毫秒)
 18337 KeyCharacterMap W否键盘ID 65540
 18337 KeyCharacterMapW¯¯使用默认的键盘对应:/system/usr/keychars/qwerty.kcm.bin
 18337 onmenuÐ{规模= 1.0 IMSI =1分之525LOC = EN_GB触摸= 3键= 1/1/2 NAV = 3/1广州澳凌= 1布局= 34 uiMode = 17 SEQ = 143}
 

之间的OnCreate和onmenu,语言环境神奇地改变了。

请帮忙,我一直在摆弄这个没有运气。

code片断:

  @覆盖
   公共无效的onCreate(包savedInstanceState){
       super.onCreate(savedInstanceState);

       配置C =新配置();
       c.locale =新的语言环境(中);
       getResources()updateConfiguration(C,空)。

       的setContentView(R.layout.main);
       Log.d(OnCreate中,getResources()getConfiguration()的toString());
   }

   @覆盖
   公共布尔onCreateOptionsMenu(功能菜单){
       Log.d(。onmenu,getResources()getConfiguration()的toString());
       新MenuInflater(本).inflate(R.menu.utama,菜单);

       返回true;
   }
 

解决方案

每100ms复位配置:)

I want to have a configurable language settings in my app.

So, in onCreate of my activity, I call Resources.updateConfigurationwith the new locale.

However, after onCreate (at some time, I can't find it when), thelocale is set back to the default locale.

On the code example below, the strings shown in the main layout (asinflated by setContentView) shows the"in" language version, BUT when I press the menu button, on whichonCreateMenu is called, the strings istaken from the "en" (default) locale.

The log shows this:

 18337               oncreate  D  { scale=1.0 imsi=525/1 loc=intouch=3 keys=1/1/2 nav=3/1 orien=1 layout=34 uiMode=17 seq=143}
 30430        ActivityManager  I  Displayed activity yuku.coba.locale/.CobaLocaleActivity: 266 ms (total 266 ms)
 18337        KeyCharacterMap  W  No keyboard for id 65540
 18337        KeyCharacterMap  W  Using default keymap: /system/usr/keychars/qwerty.kcm.bin
 18337                 onmenu  D  { scale=1.0 imsi=525/1 loc=en_GB touch=3 keys=1/1/2 nav=3/1 orien=1 layout=34 uiMode=17 seq=143}

Between "oncreate" and "onmenu", the locale magically changes.

Please help, I have been tinkering with this with no luck.

Code snippet:

   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);

       Configuration c = new Configuration();
       c.locale = new Locale("in");
       getResources().updateConfiguration(c, null);

       setContentView(R.layout.main);
       Log.d("oncreate", getResources().getConfiguration().toString());
   }

   @Override
   public boolean onCreateOptionsMenu(Menu menu) {
       Log.d("onmenu", getResources().getConfiguration().toString());
       new MenuInflater(this).inflate(R.menu.utama, menu);

       return true;
   }
解决方案

Every 100ms reset the Configuration :)

这篇关于Android的用户设置的语言环境总要得到的onCreate后重置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 13:52