//下面这是修改语言 方法
getActivity().onConfigurationChanged(AppUtil.setLocale(getActivity()));
public static Locale getLocale(Context context) { String language = PreferencesUtil.getValue(context, CommonConstants.PREFERENCE_SELECT_LANGUAGE, Locale.ENGLISH.toString());
Locale locale = new Locale(language); if (language.contains("_")) { locale = new Locale(language.substring(0,
language.indexOf("_")), language.substring( language.indexOf("_") + 1, language.length())); }
return locale;}
public static Configuration setLocale(Context context) {
Locale locale = getLocale(context); Log.e("locale isSet " + locale.toString(), "save Language = " + language); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { return updateResources(context, locale); } return updateResourcesLegacy(context, locale);}
@TargetApi(Build.VERSION_CODES.N)private static Configuration updateResources(Context context, Locale language) { Resources res = context.getResources(); Locale.setDefault(language); Configuration configuration = context.getResources().getConfiguration(); configuration.setLocale(language); res.updateConfiguration(configuration, res.getDisplayMetrics()); return configuration;}
@SuppressWarnings("deprecation")private static Configuration updateResourcesLegacy(Context context, Locale language) { Locale.setDefault(language); Resources resources = context.getResources(); Configuration configuration = resources.getConfiguration(); configuration.locale = language; resources.updateConfiguration(configuration, resources.getDisplayMetrics()); return configuration;}
java语言代码示例
回复删除java编程绘制多边形