关于Androd Locale改变,应用本身资源locale问题
来源:互联网 发布:python字符串能更改吗 编辑:程序博客网 时间:2024/06/08 09:48
After a good night of spleep, I found the answer on the Web (a simple Google search on the following line "getBaseContext().getResources().updateConfiguration(mConfig, getBaseContext().getResources().getDisplayMetrics());
"), here it is :
link text=> this link also showsscreenshots
of what is happening !
Density was the issue here, I needed to have this in the AndroidManifest.xml
<supports-screensandroid:smallScreens="true"android:normalScreens="true"android:largeScreens="true"android:anyDensity="true"/>
The most important is the android:anyDensity =" true ".
Don't forget to add the following in the manifest
(for every activity) :
android:configChanges="locale"
Through the original question is not exactly about the locale itself all other locale related questions are referencing to this one. That's why I wanted to clarify the issue here. I used this question as a starting point for my own locale switching code and found out that the method is not exactly correct. It works, but only until any configuration change (e.g. screen rotation) and only in that particular Activity. Playing with a code for a while I have ended up with the following approach:
I have extended android.app.Application and added the following code:
public class MyApplication extends Application{ private Locale locale = null; @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); if (locale != null) { newConfig.locale = locale; Locale.setDefault(locale); getBaseContext().getResources().updateConfiguration(newConfig, getBaseContext().getResources().getDisplayMetrics()); } } @Override public void onCreate() { super.onCreate(); SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); Configuration config = getBaseContext().getResources().getConfiguration(); String lang = settings.getString(getString(R.string.pref_locale), ""); if (! "".equals(lang) && ! config.locale.getLanguage().equals(lang)) { locale = new Locale(lang); Locale.setDefault(locale); config.locale = locale; getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics()); } }}
This code ensures that every Activity will have custom locale set and it will not be reset on rotation and other events.
I have also spent a lot of time trying to make the preference change to be applied immediately but didn't succeed: the language changed correctly on Activity restart, but number formats and other locale properties were not applied until full application restart.
- 关于Androd Locale改变,应用本身资源locale问题
- locale问题
- -->Locale<--
- Locale
- locale
- locale
- locale
- Locale
- locale
- Locale
- locale
- locale
- Locale
- Locale
- locale
- Locale
- locale
- 关于locale的设定
- JAVA 重载“+”
- Objective-C 的property学习
- AXIS2之WSDL2JAVA
- js loadmask
- 海量文献管理系统概述
- 关于Androd Locale改变,应用本身资源locale问题
- codeigniter 笔记一
- 使用动态内表——ALV输出
- js 表格排序
- PHP.ini配置文件中文
- 2011-11-21
- 怎么查看动态分配内存空间的大小(GNU linux下C语言版)
- C语言学习笔记之指针篇(一)
- mifare 1k卡模拟功能