Force Localize an Application on Android

Posted on by chrisonline | Comments (1) | Android Development

As the title stated, you can force your application to be localize on an application basis and not system basis. In this article we would use german and english. To do this you have to edit something on your oncreate function on your default activity.

import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;


public class Main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);


Locale locale = new Locale(Locale.GERMAN);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());


this.setContentView(R.layout.main);
}
}

Info for Android 2.0:
Add android:configChanges=”locale” to your activity nodes on the manifest file.

<activity android:name=”.Main” android:configChanges=”locale” android:label=”@string/app_name” />

Info for Motorola Milestone/Droid and compile with Android 1.5/1.6:
Add support-screens to your manifest file, else the scaling of the milestone/droid is wrong.

<supports-screensandroid:smallScreens="true"android:normalScreens="true"android:largeScreens="true"android:anyDensity="true"/>

Code Explanation:

Locale locale = new Locale(Locale.GERMAN);
Here we create a new Locale for GERMAN.

Configuration config = new Configuration();
config.locale = locale;

This creates a new Configuration and then we change the locale of this configuration with our geman locale.

getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
Here we update the configuration of our basecontext’s resources.

转自:http://android.chrisonline.at/?p=259

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. pip 最新版 发布(Python包安装和管理工具)
  2. Python处理文件的几个常用小知识
  3. 用 VS Code 写 Python,这8个扩展装上后无
  4. 超级好用的RabbitMQ 消息 100% 投递的解
  5. 入土系列 | 前端入门实战项目(四)
  6. 吊打面试官系列 | ES6 面试知识点精华篇(
  7. 动画:什么是堆?
  8. 动画:用动画给面试官解释 KMP 算法
  9. 保姆级教学:手把手教你如何实现同期群分析
  10. 考研成绩出了,你考的怎么样?