源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2021-10-21 23:40 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要: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; 
} 
[b]PS: android判断当前系统用的是什么语言[/b] [b]判断国家:[/b] 中文:[code]getResources().getConfiguration().locale.getCountry().equals("CN")[/code] 繁体中文: [code]getResources().getConfiguration().locale.getCountry().equals("TW") [/code] 英文(英式):[code]getResources().getConfiguration().locale.getCountry().equals("UK")[/code] 英文(美式):[code]getResources().getConfiguration().locale.getCountry().equals("US")[/code] 如果不清楚当前国家的简写,可以直接 [code]System.out(getResources().getConfiguration().locale.getCountry());[/code]打印出来即可 [b]下面是判断是否是中文或者繁体中文(台湾):[/b]
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; 
 } 
[code]String format = Settings.System.getString(context4Year.getContentResolver(), Settings.System.DATE_FORMAT);[/code] 以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持编程素材网!
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部