本文整理了Java中android.content.res.Configuration.setLayoutDirection()
方法的一些代码示例,展示了Configuration.setLayoutDirection()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Configuration.setLayoutDirection()
方法的具体详情如下:
包路径:android.content.res.Configuration
类名称:Configuration
方法名:setLayoutDirection
暂无
代码示例来源:origin: gunhansancar/ChangeLanguageExample
@SuppressWarnings("deprecation")
private static Context updateResourcesLegacy(Context context, String language) {
Locale locale = new Locale(language);
Locale.setDefault(locale);
Resources resources = context.getResources();
Configuration configuration = resources.getConfiguration();
configuration.locale = locale;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
configuration.setLayoutDirection(locale);
}
resources.updateConfiguration(configuration, resources.getDisplayMetrics());
return context;
}
}
代码示例来源:origin: gunhansancar/ChangeLanguageExample
@TargetApi(Build.VERSION_CODES.N)
private static Context updateResources(Context context, String language) {
Locale locale = new Locale(language);
Locale.setDefault(locale);
Configuration configuration = context.getResources().getConfiguration();
configuration.setLocale(locale);
configuration.setLayoutDirection(locale);
return context.createConfigurationContext(configuration);
}
代码示例来源:origin: pranavpandey/dynamic-support
/**
* Update resources for a given context after setting the locale on
* {@link Build.VERSION_CODES#JELLY_BEAN} or below devices.
*
* @param context The context to set update resources.
* @param locale The locale to be used for the context resources.
*
* @return The modified context after applying the locale.
*/
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private static @NonNull Context updateResourcesLegacy(
@NonNull Context context, @NonNull Locale locale) {
Locale.setDefault(locale);
Resources resources = context.getResources();
Configuration configuration = resources.getConfiguration();
configuration.locale = locale;
if (DynamicVersionUtils.isJellyBeanMR1()) {
configuration.setLayoutDirection(locale);
}
resources.updateConfiguration(configuration, resources.getDisplayMetrics());
return context;
}
}
代码示例来源:origin: pylerSM/XInstaller
@SuppressLint("NewApi")
public void initialize() {
if (mContext == null) {
return;
}
String locale = getLocale();
if (SYSTEM.equals(locale)) {
locale = Locale.getDefault().toString();
}
Locale newLocale;
if (locale.contains("_")) {
String[] loc = locale.split("_");
newLocale = new Locale(loc[0], loc[1]);
} else {
newLocale = new Locale(locale);
}
Resources resources = mContext.getResources();
if (resources == null) {
return;
}
Configuration config = resources.getConfiguration();
config.locale = newLocale;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
config.setLayoutDirection(newLocale);
}
resources.updateConfiguration(config, resources.getDisplayMetrics());
}
代码示例来源:origin: pranavpandey/dynamic-support
/**
* Update resources for a given context after setting the locale on
* {@link Build.VERSION_CODES#JELLY_BEAN_MR1} or above devices.
*
* @param context The context to set update resources.
* @param locale The locale to be used for the context resources.
*
* @return The modified context after applying the locale.
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private static @NonNull Context updateResources(
@NonNull Context context, @NonNull Locale locale) {
Locale.setDefault(locale);
Configuration configuration = new Configuration(
context.getResources().getConfiguration());
configuration.setLocale(locale);
configuration.setLayoutDirection(locale);
context.createConfigurationContext(configuration);
// Hack to fix the dialog fragment layout issue on
// configuration change.
context.getResources().updateConfiguration(configuration,
context.getResources().getDisplayMetrics());
return context;
}
代码示例来源:origin: delight-im/Android-Languages
conf.setLayoutDirection(conf.locale);
内容来源于网络,如有侵权,请联系作者删除!