Android的:如何从MM / DD / YYYY改变的DatePicker查看日期格式DD / MM / YYYY? [英] Android: How to change the DatePicker view date format from MM/dd/yyyy to dd/MM/yyyy?

查看:624
本文介绍了Android的:如何从MM / DD / YYYY改变的DatePicker查看日期格式DD / MM / YYYY?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图让一个回答这个问题相当长一段时间。我也有一个看看下面的链接:机器人 - 的DatePicker控件格式。 在我的手机/仿真器(V 2.3.3)都DatePicker的小部件和对话框不采取设置中指定的日期格式(设置 - >日期和放大器;时间 - >选择日期格式)。他们总是在格式为MM / DD / YYYY。该区域被设置为英语(英国)。

I have been trying to get an answer to this question for quite a while. I also had a look at the following link: Android - DatePicker Widget Format. On my phone/ emulator (v 2.3.3) both the DatePicker widget and the dialog do not take the date format specified in settings (Settings->Date&Time->Select date format). They are always in the format "MM/dd/yyyy". The locale is set to English UK.

我得到D / MM / YYYY当我读到的设置有:

I get "d/MM/yyyy" when I read the settings with:

Settings.System.getString(getContentResolver(),Settings.System.DATE_FORMAT);

有没有人有关于如何更改日期格式在一个datepicker视图的想法?

Does anybody have an idea about how to change the date format in a DatePicker view?

推荐答案

要覆盖的DatePicker格式化最好的选择将覆盖它的构造函数之一有轻微的编辑到原来的code。您可以编辑的ViewGroup在$ C $下你,但我会认真考虑不这样做的方式。

To override the DatePicker format the best bet would be to override one of its constructors with a slight edit to the original code. You can edit the ViewGroup in code for you but I'd seriously consider not doing it that way.

  1. 创建类LocalizedDatePicker
  2. 覆盖<一href="http://developer.android.com/reference/android/widget/DatePicker.html#DatePicker%28android.content.Context,%20android.util.AttributeSet,%20int%29"相对=nofollow>公开的DatePicker(上下文的背景下,ATTRS的AttributeSet,INT defStyle) <一href="http://developer.android.com/reference/android/widget/DatePicker.html#DatePicker(android.content.Context" rel="nofollow">http://developer.android.com/reference/android/widget/DatePicker.html#DatePicker(android.content.Context, android.util.AttributeSet,INT)
  3. 复制从<一的code href="https://android.googlesource.com/platform/frameworks/base/+/HEAD/core/java/android/widget/DatePicker.java"相对=nofollow>原来的DatePicker构造(您可能需要选择在一些测试不同的分支,我已经挂了头)
  4. 调用reorderSpinners
  5. 在覆盖()的方法来消除这一呼吁。
  6. 替换行 inflater.inflate(R.layout.date_picker,这个,真); inflater.inflate(my.package.R。 layout.localized_date_picker,这个,真);
  7. 复制原date_picker.xml布局,以当地资源localized_date_picker.xml
  8. 编辑所需的顺序文件,因为您正在编辑该请尊重其他地方的定位,并保持原有的副本在您的全球布局文件夹,并把localized_date_picker.xml在您所在地区指定的文件夹。由于系统的布局是月日年人在其他地方可能期望的顺序。
  1. Create class LocalizedDatePicker
  2. Override public DatePicker (Context context, AttributeSet attrs, int defStyle) http://developer.android.com/reference/android/widget/DatePicker.html#DatePicker(android.content.Context, android.util.AttributeSet, int)
  3. Copy the code from the original DatePicker constructor (you may need to select a different branch after some testing, I have linked the head)
  4. Override methods that call reorderSpinners() to remove that call.
  5. Replace line inflater.inflate(R.layout.date_picker, this, true); with inflater.inflate(my.package.R.layout.localized_date_picker, this, true);
  6. Copy the original date_picker.xml layout to your local resource localized_date_picker.xml
  7. Edit the file for the desired order, since you're editing this please respect the localization of other places and keep a copy of the original in your global layout folder and put the localized_date_picker.xml in your region specific folder. Since the system's layout is Month Day Year people in other places may expect that order.

这篇关于Android的:如何从MM / DD / YYYY改变的DatePicker查看日期格式DD / MM / YYYY?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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