如何在android中单独获取应用程序语言和设备语言?

Deb*_*ger 23 android locale localization setlocale

我的设备语言是英文的,我的应用程序语言是意大利语.那么我将如何以编程方式获得语言设备语言和应用程序语言?

Els*_*oty 43

获得系统语言

Resources.getSystem().getConfiguration().locale.getLanguage();
Run Code Online (Sandbox Code Playgroud)

获得应用语言

String CurrentLang = Locale.getDefault().getLanguage();
Run Code Online (Sandbox Code Playgroud)

  • “获取应用语言”是什么意思?如果系统设置为应用程序不支持的语言,则两者都将返回系统语言,即使应用程序以不同的语言显示。 (4认同)
  • Resources.getSystem().getConfiguration().locale.getLanguage() 已弃用 (2认同)

Ahm*_*aiz 7

这是正确答案:getResources().getConfiguration().locale


Ale*_*ano 7

Kotlin - Android X:

val currentSysLocale = Resources.getSystem().getConfiguration().locales[0]
val currentAppLocale = Locale.getDefault().getLanguage()
Log.d("sys locale","$currentSysLocale")
Log.d("app locale","$currentAppLocale")
Run Code Online (Sandbox Code Playgroud)


Kau*_*iya 6

获取系统语言使用这个:

String DeviceLang =Resources.getSystem().getConfiguration().locale.getLanguage();
Run Code Online (Sandbox Code Playgroud)

对于应用程序语言,请使用:

String AppLang = Resources.getConfiguration().locale.getLanguage();
Run Code Online (Sandbox Code Playgroud)