Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Context wrap(Context context, Locale locale) {
- Configuration config = context.getResources().getConfiguration();
- if (locale == null) locale = Locale.ENGLISH; //Your default locale
- Locale.setDefault(locale);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
- config.setLocale(locale);
- } else {
- config.locale = locale;
- }
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
- return context.createConfigurationContext(config);
- } else {
- context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());
- return context;
- }
- }
Add Comment
Please, Sign In to add comment