Android:如何设置应用程序的文化值
)我是一名 C# 开发人员,现在我开始为 Android 编写应用程序。在 C# 中,我们有 CultureInfo 对象,可以在其中设置应用程序区域性的值。 java(android)中有一个类似的对象可以让我做到这一点??我发现我可以使用 Locale.setDefault(Locale.FRENCH); 设置区域设置但我如何设置日期、数字和货币符号???
这是我使用的 C# 代码:
CultureInfo objCultureInfo = new CultureInfo("en-US", true);
objCultureInfo.NumberFormat.NumberDecimalDigits = 2;
objCultureInfo.NumberFormat.NumberDecimalSeparator = ".";
objCultureInfo.NumberFormat.NumberGroupSeparator = ",";
objCultureInfo.DateTimeFormat.DateSeparator = "/";
objCultureInfo.DateTimeFormat.TimeSeparator = ":";
objCultureInfo.DateTimeFormat.FullDateTimePattern = "MM/dd/yyyy HH:mm:ss";
objCultureInfo.DateTimeFormat.ShortDatePattern = "MM/dd/yyyy";
objCultureInfo.DateTimeFormat.ShortTimePattern = "HH:mm:ss";
objCultureInfo.NumberFormat.CurrencySymbol = "$";
Cultura.CulturaAplicacion = objCultureInfo;
谢谢!
) i'm a C# developer and now i started to program apps for android. In C# we have the CultureInfo object where we can set the values for the culture of the aplication. There is a similar object in java (android) to let me do that ¿? i found that i can set the locale with this Locale.setDefault(Locale.FRENCH); but how i set the date, number adn monetaris symbols ¿?
Here is the code in C# that i use:
CultureInfo objCultureInfo = new CultureInfo("en-US", true);
objCultureInfo.NumberFormat.NumberDecimalDigits = 2;
objCultureInfo.NumberFormat.NumberDecimalSeparator = ".";
objCultureInfo.NumberFormat.NumberGroupSeparator = ",";
objCultureInfo.DateTimeFormat.DateSeparator = "/";
objCultureInfo.DateTimeFormat.TimeSeparator = ":";
objCultureInfo.DateTimeFormat.FullDateTimePattern = "MM/dd/yyyy HH:mm:ss";
objCultureInfo.DateTimeFormat.ShortDatePattern = "MM/dd/yyyy";
objCultureInfo.DateTimeFormat.ShortTimePattern = "HH:mm:ss";
objCultureInfo.NumberFormat.CurrencySymbol = "$";
Cultura.CulturaAplicacion = objCultureInfo;
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在我看来,您根本不应该更改 Locale 值。用户在设置中广泛设置该值设备。您还可以在那里设置日期和时间格式。您应该在应用程序中使用这些值,而不是用自定义值覆盖它们,因为用户更了解他/她想要使用哪种语言和格式。
In my opinion you shouldn't change the Locale value at all. The user sets this value device wide in the settings. You can also set your date and time format there, too. You should use those values in your app instead of overriding them with custom ones, because the user knows better, which language and formats he/she wants to use.
我想我在这里找到了我需要的东西:
http://developer.android.com/参考/java/text/NumberFormat.html
谢谢!
I think I found what I needed here:
http://developer.android.com/reference/java/text/NumberFormat.html
Thanks!