DatePickerDialog 错误地强制执行了 1970 年 1 月 1 日的最小日期 [英] DatePickerDialog incorrectly enforcing a minimum date of Jan 1, 1970

查看:33
本文介绍了DatePickerDialog 错误地强制执行了 1970 年 1 月 1 日的最小日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个成员报告说他无法在我们的 DatePickerDialog 上设置 1970 年 1 月 1 日之前的日期.这个问题不适合我们.

We have a member reporting that he is unable to set a date before Jan 1, 1970 on our DatePickerDialog. This issue does not repro for us.

我已经知道 DatePickerDialog 没有公开基础 DatePicker 的 setMinDate/setMaxDate 函数,因此似乎某种手机制造商特定的修改正在影响 minDate/maxDate.

I am already aware that the DatePickerDialog does not expose the setMinDate/setMaxDate functions of the underlying DatePicker, so it would seem that some kind of handset maker-specific modification is affecting the minDate/maxDate.

该用户报告说,他在运行 2.2 Froyo 的 Verizon 上运行 Droid x2.虽然我们认为他对设备型号的描述是正确的,但许多用户对操作系统版本感到困惑,因此他可能运行的是 2.3.

This user reports he is running a Droid x2 on Verizon running 2.2 Froyo. While we believe he is correct in his description of his device model, many users are confused about the OS version, so he may be running 2.3.

我试图通过将这个主题添加到我的活动来解决这个问题:

I attempted to solve this problem by adding this theme to my Activity:

<style name="profile_editor_theme">     
    <item name="android:endYear">2025</item>
    <item name="android:startYear">1910</item>
</style>

虽然这个主题在我的活动中具有在我的测试设备(一个 Galaxy 选项卡和一个原始的摩托罗拉 Droid)上限制 DatePickerDialog 的预期效果,但它显然对用户没有影响.

While this theme on my activity had the intended effect of constraining the DatePickerDialog on my test devices (a Galaxy tab and an original Motorola Droid), it apparently had no effect for the user.

这个问题在 100% 的时间为我们的用户重现,但在我们自己的设备上正常工作.

This issue repros for our user 100% of the time, but works correctly for us on our own devices.

谁能解释一下可能导致这种情况的原因以及我们如何解决它?

Can anyone explain what might be causing this and how we could fix it?

我已经针对谷歌在这个问题上.

谢谢!

推荐答案

Android 设备的开始日期从 1970 年 1 月 1 日开始.也许这就是您的情况.Android 将时间计算为自 1970 年 1 月 1 日以来经过的毫秒数.

Starting date of Android devices starts from Jan 1, 1970. Maybe this can be your case. Android calculates time as a number of milliseconds passed since Jan 1, 1970.

我为您的案例找到了一种破解方法.这里我动态创建 datePicker:

I've found a kind of hack for your case. Here I create dynamically datePicker:

     DatePicker dp = new DatePicker(this);
     dp.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
     v.addView(dp);

在清单文件中,我为我的应用程序声明了一个自定义主题 - 我希望应用程序具有相同的主题.顺便说一句,您可以对活动做同样的事情.

In the manifest file I declare a custom theme for my application - I want the same theme for the application. By the way you can do the same for activity.

 <application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" 
    android:theme="@style/CustomTheme">
    <activity
        android:name=".HelloDatePickerActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

在styles.xml中我这样做:

In a styles.xml I do this:

<style name="CustomTheme" parent="android:Theme.Light">
    <item name="android:startYear">1890</item>
</style>

在我的情况下,默认开始日期是 1900.因此,对我来说,这种方法有效.

The default start date in my case is 1900. Thus, for me this approach works.

希望对你有帮助!

这篇关于DatePickerDialog 错误地强制执行了 1970 年 1 月 1 日的最小日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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