温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2020-09-10 22:16:13 来源:脚本之家 阅读:418 作者:ganchuanpu 栏目:移动开发

话不多说,请看代码:

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

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

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI