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

 更新时间:2017年04月12日 08:23:39   作者:ganchuanpu  
本文主要介绍了Android 判断当前语言环境是否是中文环境的方法。具有很好的参考价值。下面跟着小编一起来看下吧

话不多说,请看代码:

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);

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持脚本之家!

相关文章

最新评论