android修改显示语言简单实现

来源:互联网 发布:鼠标测试软件 编辑:程序博客网 时间:2024/06/05 16:20

简单的写下,。

public static void switchLanguage(String language, Context context) {Locale aLocale;if (language.equals("cn")) {aLocale = Locale.SIMPLIFIED_CHINESE;} else if (language.equals("cnt")) {aLocale = Locale.TRADITIONAL_CHINESE;} else {aLocale = new Locale(language);}Resources resources = context.getResources();// 获得res资源对象Configuration config = resources.getConfiguration();// 获得设置对象DisplayMetrics dm = resources.getDisplayMetrics();// 获得屏幕参数:主要是分辨率,像素等。config.locale = aLocale; resources.updateConfiguration(config, dm);}


可以在menifest里面加这么一句话:

<supports-screens android:anyDensity="true"/>

0 0
原创粉丝点击