如何显示最新的DatePickerDialog和TimePickerDialog android

时间:2014-06-15 16:37:05

标签: android android-layout android-datepicker android-timepicker

我想在创建这些对话框时我犯了一些基本错误,因为我无法就我遇到的问题找到任何问题。

我正在尝试在我的应用程序中显示最新的对话框(从3.0引入时间和日期),然后我跟随developer's site的链接。我的应用程序仅支持4.0及更高版本的设备,因此这不应该是一个问题。

我想,当我点击按钮调用日期或时间选择器时,我会看到类似下面的内容......

enter image description here

但是,这就是我得到的......我认为这是一个古老的日期选择器

enter image description here

我的XML for按钮触发对话..

   <Button
        android:id="@+id/button_end_date"
        style="?android:attr/buttonBarButtonStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="showDatePickerDialog"
        android:text="@string/button_enddate" />

对于java部分,我添加了开发人员网站的代码,我猜这里不需要。

我做错了什么?

3 个答案:

答案 0 :(得分:1)

像android中的大多数视图一样的选择器依赖于os版本。非常简单的UI元素,如按钮看起来在姜饼和kitkat版本的OS中视觉上有所不同。如果您使用的是原生选择器,除了更改样式外,您可以做的很少。但是你提到你使用的是4.0+,所以你得到一个旧的对话框,我自己尝试了这个代码并且得到了类似的结果,这似乎有点奇怪。我只能提出一些建议:

  1. 在xml中添加datepicker和时间选择器。它不需要是一个扩展DialogFragment
  2. 的类
  3. 尝试自定义主题
  4. DatePickerDialog(Context context, int theme, DatePickerDialog.OnDateSetListener callBack, int year, int monthOfYear, int dayOfMonth) //您也可以为日期选择器对话框设置主题。 下面是我的代码的一些快照: enter image description here 请注意,默认情况下您没有设置和取消按钮。你只做了按钮。

答案 1 :(得分:1)

要使用Holo主题,styles.xml中的应用主题必须有Theme.Holo.*个父母。

像:

<style name="AppTheme" parent="@style/Theme.Holo.Light"> ... </style>
or
<style name="AppTheme" parent="@style/Theme.Holo"> ... </style>

答案 2 :(得分:0)

您可能在应用程序或活动中设置了错误的样式。在我的情况下,我正在使用Manifest中的每个活动一个android:theme =“@ android:style / Theme.NoTitleBar.Fullscreen”主题。 我现在正在使用自定义应用主题,它正在运行:

<style name="AppTheme" parent="@style/Theme.AppCompat">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowNoTitle">true</item>
</style>