Android 判断当前语言环境是否是中文环境

来源:互联网 发布:dt数据时代 编辑:程序博客网 时间:2024/06/07 05:35

http://www.jb51.net/article/110935.htm


话不多说,请看代码:

public static boolean isZh(Context context) {  Locale locale = context.getResources().getConfiguration().locale;  String language = locale.getLanguage();  if (language.endsWith("zh"))  return true;  else  return false; } 

PS: android判断当前系统用的是什么语言

判断国家:

中文:getResources().getConfiguration().locale.getCountry().equals("CN")

繁体中文: getResources().getConfiguration().locale.getCountry().equals("TW")

英文(英式):getResources().getConfiguration().locale.getCountry().equals("UK")

英文(美式):getResources().getConfiguration().locale.getCountry().equals("US")

如果不清楚当前国家的简写,可以直接

System.out(getResources().getConfiguration().locale.getCountry());打印出来即可

下面是判断是否是中文或者繁体中文(台湾):

public boolean isLunarSetting() {   String language = getLanguageEnv();    if (language != null     && (language.trim().equals("zh-CN") || language.trim().equals("zh-TW")))    return true;   else    return false;  } 
private String getLanguageEnv() {   Locale l = Locale.getDefault();   String language = l.getLanguage();   String country = l.getCountry().toLowerCase();   if ("zh".equals(language)) {    if ("cn".equals(country)) {     language = "zh-CN";    } else if ("tw".equals(country)) {     language = "zh-TW";    }   } else if ("pt".equals(language)) {    if ("br".equals(country)) {     language = "pt-BR";    } else if ("pt".equals(country)) {     language = "pt-PT";    }   }   return language;  } 

String format = Settings.System.getString(context4Year.getContentResolver(), Settings.System.DATE_FORMAT);


原创粉丝点击