android:layout_marginEnd="15dp"<vector android:autoMirrored="true">| 配置 | 示例 | 说明 |
|---|---|---|
| MCC和MNC | mcc310 | 移动国家代码 |
| 语言和区域 | en | 语言通过由两个字母组成的ISO 639-1语言代码定义 |
| 布局方向 | ldrtl ldltr |
ldltr是默认值,要为应用启用从右到左的布局功能,必须将 supportsRtl 设置为 “true”,并将 targetSdkVersion 设置为 17 或更高版本 |
public int getLayoutDirection() {
return (screenLayout&SCREENLAYOUT_LAYOUTDIR_MASK) == SCREENLAYOUT_LAYOUTDIR_RTL
? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR;
}强制设置配置
private void resetLocal() {
Configuration config = getResources().getConfiguration();
Locale locale = App.appLocale();
Locale.setDefault(locale);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
config.setLocale(locale);
config.setLayoutDirection(locale);
} else {
config.locale = locale;
}
getResources().updateConfiguration(config, getResources().getDisplayMetrics());
}
getResources().updateConfiguration()方法在17版本以后过时,替换为下面的方法
ContextWrapper public Context createConfigurationContext (Configuration overrideConfiguration
public static String timeFormat(long time, String locale) {
DateFormat dateFormat1 = new SimpleDateFormat("HH:mm dd-MM-yyyy", Locale.CHINA);
dateFormat1.setTimeZone(TimeZone.getTimeZone("GMT+3"));
//dateFormat.setTimeZone(TimeZone.getTimeZone(locale));
return dateFormat1.format(time);
}
字符串的格式化,可以使用有两个参数的format方法
public static String format(Locale l, String format, Object... args) {
return new Formatter(l).format(format, args).toString();
}
TextView中设置显示的语言 防止例如在阿拉伯语环境下,数字会以阿拉伯语的方式展示
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
textView.setTextLocale(Locale.ENGLISH);
}