安卓获取当前的语言环境,没有违约 [英] Android get current Locale, not default

查看:193
本文介绍了安卓获取当前的语言环境,没有违约的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取用户当前的语言环境中的Andr​​oid?

How do I get the user's current Locale in Android?

我可以得到默认的,但是这可能不是当前是否正确?

I can get the default one, but this may not be the current one correct?

基本上我想从目前的语言环境的两个字母的语言code。不是默认之一。没有 Locale.current()

Basically I want the two letter language code from the current locale. Not the default one. There is no Locale.current()

推荐答案

默认区域设置从系统属性设置的静态构造函数在运行时为您的应用程序,所以它将重新present的区域设置该设备的当应用程序的启动的选择。通常情况下,这是好的,但它确实意味着,如果用户更改其区域设置在正在运行的应用程序后设置,的getDefaultLocale值( )可能不会立即更新。

The default Locale is constructed statically at runtime for your application process from the system property settings, so it will represent the Locale selected on that device when the application was launched. Typically, this is fine, but it does mean that if the user changes their Locale in settings after your application process is running, the value of getDefaultLocale() probably will not be immediately updated.

如果你需要这样的陷阱事件由于某种原因,在应用程序中,你可能会改为尝试获得区域设置可从资源配置对象,即

If you need to trap events like this for some reason in your application, you might instead try obtaining the Locale available from the resource Configuration object, i.e.

Locale current = getResources().getConfiguration().locale;

您可能会发现,这个值被更新更迅速地经过设置改变,如果这是必要的应用程序。

You may find that this value is updated more quickly after a settings change if that is necessary for your application.

这篇关于安卓获取当前的语言环境,没有违约的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆