本文整理匯總了Java中android.content.res.Resources.updateConfiguration方法的典型用法代碼示例。如果您正苦於以下問題:Java Resources.updateConfiguration方法的具體用法?Java Resources.updateConfiguration怎麽用?Java Resources.updateConfiguration使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.content.res.Resources
的用法示例。
在下文中一共展示了Resources.updateConfiguration方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: checkLanguage
import android.content.res.Resources; //導入方法依賴的package包/類
private void checkLanguage() {
SharedPreferences sharedPreferences = this.getSharedPreferences("set", MODE_PRIVATE);
/**
* 獲取係統配置
*/
Resources resources = getResources();
DisplayMetrics dm = resources.getDisplayMetrics();
Configuration config = resources.getConfiguration();
if (LANGUAGE_CN.equals(sharedPreferences.getString("language", "0"))) {
config.locale = Locale.SIMPLIFIED_CHINESE;
resources.updateConfiguration(config, dm);
} else if (LANGUAGE_EN.equals(sharedPreferences.getString("language", "0"))) {
config.locale = Locale.ENGLISH;
resources.updateConfiguration(config, dm);
} else {
config.locale = Locale.SIMPLIFIED_CHINESE;
resources.updateConfiguration(config, dm);
}
}
示例2: onCreate
import android.content.res.Resources; //導入方法依賴的package包/類
@Override
public void onCreate() {
super.onCreate();
Resources resources = getResources();
DisplayMetrics dm = resources.getDisplayMetrics();
Configuration config = resources.getConfiguration();
// 應用用戶選擇語言
String language = SPUtil.getInstance(this).getLanguage();
if ("".equals(language)){
language =Locale.getDefault().getLanguage();
}
if (language.equals(SPUtil.LANGUAGE_CHINESE)) {
config.setLocale(Locale.getDefault());
} else {
config.setLocale(Locale.ENGLISH);
}
resources.updateConfiguration(config, dm);
mContext=getApplicationContext();
}
示例3: changeLanguage
import android.content.res.Resources; //導入方法依賴的package包/類
public static void changeLanguage(Context context) {
Resources resources = context.getResources();
DisplayMetrics dm = resources.getDisplayMetrics();
Configuration config = resources.getConfiguration();
switch (SharedPreManager.getInstance().getLanguage(context)) {
case Constant.LANGUAGE_CHINA:
config.locale = Locale.SIMPLIFIED_CHINESE;
break;
case Constant.LANGUAGE_ENGLISH:
config.locale = Locale.ENGLISH;
break;
case Constant.LANGUAGE_DEFAULT:
config.locale = Locale.getDefault();
break;
}
// 應用用戶選擇語言
resources.updateConfiguration(config, dm);
}
示例4: hasDictionary
import android.content.res.Resources; //導入方法依賴的package包/類
private boolean hasDictionary(Locale locale, Context ctx) {
Resources res = getResources();
Configuration conf = res.getConfiguration();
Locale saveLocale = conf.locale;
boolean haveDictionary = false;
conf.locale = locale;
res.updateConfiguration(conf, res.getDisplayMetrics());
//somewhat a hack. But simply querying the dictionary will always return an English
//dictionary in KP2A so if we get a dict, we wouldn't know if it's language specific
if (locale.getLanguage().equals("en"))
{
haveDictionary = true;
}
else
{
BinaryDictionary plug = PluginManager.getDictionary(getApplicationContext(), locale.getLanguage());
if (plug != null) {
plug.close();
haveDictionary = true;
}
}
conf.locale = saveLocale;
res.updateConfiguration(conf, res.getDisplayMetrics());
return haveDictionary;
}
示例5: runInLocale
import android.content.res.Resources; //導入方法依賴的package包/類
/**
* Execute {@link #job(Resources)} method in specified system locale exclusively.
*
* @param res the resources to use.
* @param newLocale the locale to change to. Run in system locale if null.
* @return the value returned from {@link #job(Resources)}.
*/
public T runInLocale(final Resources res, final Locale newLocale) {
synchronized (sLockForRunInLocale) {
final Configuration conf = res.getConfiguration();
if (newLocale == null || newLocale.equals(conf.locale)) {
return job(res);
}
final Locale savedLocale = conf.locale;
try {
conf.locale = newLocale;
res.updateConfiguration(conf, null);
return job(res);
} finally {
conf.locale = savedLocale;
res.updateConfiguration(conf, null);
}
}
}
示例6: changeLocale
import android.content.res.Resources; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
public static void changeLocale(String locale) {
Context context = InstrumentationRegistry.getInstrumentation()
.getTargetContext();
Resources res = context.getApplicationContext().getResources();
Configuration config = res.getConfiguration();
config.setLocale(new Locale(locale));
if (SDK_INT >= 25) {
context.createConfigurationContext(config);
} else {
res.updateConfiguration(config, res.getDisplayMetrics());
}
}
示例7: updateConfigurationForNightMode
import android.content.res.Resources; //導入方法依賴的package包/類
private boolean updateConfigurationForNightMode(int mode) {
Resources res = this.mContext.getResources();
Configuration conf = res.getConfiguration();
int currentNightMode = conf.uiMode & 48;
int newNightMode = 0;
switch (mode) {
case 1:
newNightMode = 16;
break;
case 2:
newNightMode = 32;
break;
}
if (currentNightMode == newNightMode) {
return false;
}
conf.uiMode = (conf.uiMode & -49) | newNightMode;
res.updateConfiguration(conf, null);
return true;
}
示例8: initTextSize
import android.content.res.Resources; //導入方法依賴的package包/類
/**
* 使其係統更改字體大小無效
*/
private void initTextSize() {
Resources res = getResources();
Configuration config = new Configuration();
config.setToDefaults();
res.updateConfiguration(config, res.getDisplayMetrics());
}
示例9: setLocale
import android.content.res.Resources; //導入方法依賴的package包/類
/**
* Set the app to use the given locale. Useful for testing translations. This is normally
* not needed because the device locale is applied automatically.
* @param context - context from which to get resources
* @param locale - the locale to use
*/
public static void setLocale(@NonNull Context context, @NonNull Locale locale) {
Locale.setDefault(locale);
Resources res = context.getResources();
DisplayMetrics dm = res.getDisplayMetrics();
android.content.res.Configuration conf = res.getConfiguration();
conf.locale = Locale.getDefault();
res.updateConfiguration(conf, dm);
}
示例10: getResources
import android.content.res.Resources; //導入方法依賴的package包/類
@Override
public Resources getResources() {
//保持字體不變
Resources res = super.getResources();
Configuration config = new Configuration();
config.setToDefaults();
res.updateConfiguration(config, res.getDisplayMetrics());
return res;
}
示例11: updateConfiguration
import android.content.res.Resources; //導入方法依賴的package包/類
private void updateConfiguration() {
if (JarApplication.getInstance() != null && JarApplication.getInstance().getResources() != null) {
Resources superRes = JarApplication.getInstance().getResources();
Configuration configuration = superRes.getConfiguration();
DisplayMetrics displayMetrics = superRes.getDisplayMetrics();
JarResources jarResources = getOverrideResources();
if (jarResources != null) {
Resources resources = jarResources.getResources();
if (resources != null && configuration != null && displayMetrics != null) {
resources.updateConfiguration(configuration, displayMetrics);
}
}
}
}
示例12: applyLanguageForContext
import android.content.res.Resources; //導入方法依賴的package包/類
/**
* Setting {@link Locale} for {@link Context}.
*/
@NonNull
public static Context applyLanguageForContext(@NonNull Context context, @NonNull Locale locale) {
Resources resources = context.getResources();
Configuration config = resources.getConfiguration();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
config.setLocale(locale);
return context.createConfigurationContext(config);
} else {
config.locale = locale;
resources.updateConfiguration(config, resources.getDisplayMetrics());
return context;
}
}
示例13: setLocale
import android.content.res.Resources; //導入方法依賴的package包/類
public void setLocale(String lang) {
Locale myLocale = new Locale(lang);
Resources res = getResources();
DisplayMetrics dm = res.getDisplayMetrics();
Configuration conf = res.getConfiguration();
conf.locale = myLocale;
res.updateConfiguration(conf, dm);
Intent refresh = new Intent(getContext(), MainActivity.class);
startActivity(refresh);
getActivity().finish();
}
示例14: getResources
import android.content.res.Resources; //導入方法依賴的package包/類
@Override
public Resources getResources() {
Resources res = super.getResources();
if (res.getConfiguration().fontScale != 1) {//非默認值
Configuration newConfig = new Configuration();
newConfig.setToDefaults();//設置默認
res.updateConfiguration(newConfig, res.getDisplayMetrics());
}
return res;
}
示例15: changeLanguage
import android.content.res.Resources; //導入方法依賴的package包/類
/**
* Нөөц дэх хэлний файлууд уншиж текстүүд орчуулах
*
* @param lang res/values/strings xml файлаас ямар хэл сонгохыг заана
*/
private void changeLanguage(String lang) {
Resources res = getApplicationContext().getResources();
DisplayMetrics dm = res.getDisplayMetrics();
android.content.res.Configuration conf = res.getConfiguration();
conf.locale = new Locale(lang);
res.updateConfiguration(conf, dm);
prefManager.setLanguage(lang.toUpperCase());
Intent intent = new Intent(ActivitySplashScreen.this, ActivityWelcome.class);
startActivity(intent);
finish();
}