Add language selector (#80), Remove force english language [Beta]
parent
328ee8da9a
commit
0f6264b15e
@ -0,0 +1,40 @@
|
||||
package com.fox2code.mmm.compat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Build;
|
||||
import android.os.LocaleList;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class CompatWrapper extends android.content.ContextWrapper {
|
||||
|
||||
public CompatWrapper(Context base) {
|
||||
super(base);
|
||||
}
|
||||
|
||||
public static ContextWrapper setLocale(Context context, Locale newLocale) {
|
||||
|
||||
Resources res = context.getResources();
|
||||
Configuration configuration = res.getConfiguration();
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
configuration.setLocale(newLocale);
|
||||
|
||||
LocaleList localeList = new LocaleList(newLocale);
|
||||
LocaleList.setDefault(localeList);
|
||||
configuration.setLocales(localeList);
|
||||
|
||||
context = context.createConfigurationContext(configuration);
|
||||
|
||||
} else {
|
||||
configuration.setLocale(newLocale);
|
||||
context = context.createConfigurationContext(configuration);
|
||||
|
||||
}
|
||||
|
||||
return new ContextWrapper(context);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue