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

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值