Force Localize an Application on Android
Force Localize an Application on Android
9. Februar 2010 Comments (1) Android DevelopmentAs 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,
Here we update the configuration of our basecontext’s resources.
getBaseContext().getResources().getDisplayMetrics());
转自:http://android.chrisonline.at/?p=259
更多相关文章
- 代码中设置drawableleft
- android 3.0 隐藏 系统标题栏
- Android开发中activity切换动画的实现
- Android(安卓)学习 笔记_05. 文件下载
- Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
- 技术博客汇总
- android 2.3 wifi (一)
- AndRoid Notification的清空和修改
- Android中的Chronometer