Guest User

Untitled

a guest
Mar 21st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. public static Context wrap(Context context, Locale locale) {
  2. Configuration config = context.getResources().getConfiguration();
  3. if (locale == null) locale = Locale.ENGLISH; //Your default locale
  4. Locale.setDefault(locale);
  5. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
  6. config.setLocale(locale);
  7. } else {
  8. config.locale = locale;
  9. }
  10. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
  11. return context.createConfigurationContext(config);
  12. } else {
  13. context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());
  14. return context;
  15. }
  16. }
Add Comment
Please, Sign In to add comment