Android 更改设备的语言设置(区域设置)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2596352/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change language settings (locale) for the device
提问by Raymond Chenon
I know it's possible to have multiple languages in a single application through the res/string and depending on Locale. Here is a case (ANDROID) controling the user language
我知道可以通过 res/string 并根据区域设置在单个应用程序中使用多种语言。这是一个控制用户语言的案例 (ANDROID)
Now how can I change the language in the phone ? Like I'd do by Menu > Settings > Language & Keyboard > Select locale > languages
现在如何更改手机中的语言?就像我通过菜单 > 设置 > 语言和键盘 > 选择区域设置 > 语言所做的那样
Is there some real code to access to these settings ? Or should I create intent for a shortcut to the language settings. Please post some code
是否有一些真正的代码可以访问这些设置?或者我应该为语言设置的快捷方式创建意图。请贴一些代码
Edit : With Locale class developer.android.com/intl/fr/reference/java/util/Locale.html
编辑:使用语言环境类 developer.android.com/intl/fr/reference/java/util/Locale.html
The constructor is at least Locale(String language) The input is language. How can you retrieve the current language used on the device ?
构造函数至少是 Locale(String language) 输入是语言。如何检索设备上使用的当前语言?
回答by Jim Blackler
Not sure about setting it directly from the app, but if you want to send the user there to change it themselves, try this:
不确定是否直接从应用程序设置它,但是如果您想将用户发送到那里自己更改它,请尝试以下操作:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.android.settings", "com.android.settings.LanguageSettings");
startActivity(intent);
回答by Sergey
There is another way to open system settings to change the language:
还有另一种打开系统设置来更改语言的方法:
Intent i = new Intent( android.provider.Settings.ACTION_LOCALE_SETTINGS );
startActivity( i );
It shows just the list of languages, and when you choose one - it changes the language on the device.
它仅显示语言列表,当您选择一种语言时,它会更改设备上的语言。
回答by Raymond Chenon
I found another answer to my own question. There is an open source code project code.google.com/p/languagepickerwidgetIt's recreating a ListActivity to display and pick the languages.
我找到了我自己问题的另一个答案。有一个开源代码项目code.google.com/p/languagepickerwidget它正在重新创建一个 ListActivity 来显示和选择语言。
Jim , your solution is much simple and exactly what I needed. It's a shorcut to the settings. Immediately after you published, I uploaded an app called "raygional" on the market. If I could (I only have 6 points) I'd make your answer useful.
Jim ,您的解决方案非常简单,正是我所需要的。这是设置的快捷方式。你发布后,我立即在市场上上传了一个名为“raygional”的应用程序。如果可以的话(我只有 6 分)我会让你的回答有用。
There is another way to see the processes and intents. On the emulator go to Menu > Dev Tools > Development Settings > and click on Show running processes
还有另一种方式可以查看流程和意图。在模拟器上转到 Menu > Dev Tools > Development Settings > 然后单击 Show running processes
回答by Edu Zamora
As far as I know, the only way to change the Locale of the device without using Intents (what the other solutions propose) is accessing internal classes through reflection (with the risks that this implies).
据我所知,在不使用意图(其他解决方案提出的)的情况下更改设备区域设置的唯一方法是通过反射访问内部类(这意味着存在风险)。
You can find an exact example for this use case here: http://www.tutorialforandroid.com/2010/07/access-internal-classes-in-android.html
您可以在此处找到此用例的确切示例:http: //www.tutorialforandroid.com/2010/07/access-internal-classes-in-android.html
回答by caller9
To expand on Jim's answer if you change the intent to:
如果您将意图更改为:
intent.setClassName("com.android.settings", "com.android.settings.LocalePicker");
It will drop the user off directly in the language selection list and once a language is selected it will return to your application.
它会将用户直接放在语言选择列表中,一旦选择了一种语言,它将返回到您的应用程序。
It removes a click, doesn't make the user think about which of the three (language, dictionary, and keyboard) options to choose and returns to your app immediately after selection.
它消除了点击,不会让用户考虑选择三个(语言、字典和键盘)选项中的哪一个,并在选择后立即返回到您的应用程序。