日期和时间选择器对话框 [英] Date and time picker dialog
问题描述
我想创建一个可以选择的时间一个对话框,并在日期在同一时间。
我知道,没有一个默认的小工具,可以做到这一点在Android 。我也知道,有开源项目中如何做类似的工作。在这个项目中的问题是,在该对话框中,我们有两个按钮:日期选择的和的 timePicker 的
这不是我想做的事 - 我要的日期和时间选择器出现的同时
所以我觉得这两个主要问题将是:
- 首先让时间和日期选择器出现在同一个对话框。
- 而第二个问题将是改变的时间和日期选择器(橙色)的出现。
第一个问题是由BHAVESH解决。下面是我所得到的:
现在的问题是,我想改变这一切的蓝条色的到的橙色的。照片
我加了安卓calendarViewShown =假
删除在正确的日历:)谢谢BHAVESH,我改变了主题的 HOLO 的
下面是我所得到的:
您也可以下载code(这是最好的我能做到)。您可以从这里 下载。
首先让时间和日期选择器出现在同一个对话框
在这里,我可以帮你些什么:你可以创建一个布局包括一个的DatePicker
和 TimePicker
的一个的LinearLayout
的方向设定为垂直。
custom_dialog.xml:
< XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID / linearLayout1
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:方向=垂直>
<的DatePicker
机器人:ID =@ + ID / datePicker1
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT>
< / DatePicker的>
< TimePicker
机器人:ID =@ + ID / timePicker1
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT>
< / TimePicker>
< / LinearLayout中>
然后用这个布局创建对话框。
对话对话框=新的对话框(mContext);
dialog.setContentView(R.layout.custom_dialog);
dialog.setTitle(自定义对话框);
要反应与交互的用户的 TimePicker
,做这样的事情:
TimePicker TP =(TimePicker)dialog.findViewById(R.id.timepicker1);
tp.setOnTimeChangedListener(myOnTimechangedListener);
要在日期 - 和TimePicker得到的值当用户完成设置,在对话框中添加一个确定按钮,然后读取来自日期 - 和TimePicker用户presses的日期和时间值确定。
要做出一些看起来完全一样在你的屏幕截图,我建议你做所有的东西定制你自己的逻辑。
I want to create a dialog which can select the time and the date at the same time.
I know that there is not a default widget that can do that on Android. I also know that there are open source projects on how do similar staff. The problem in this project is that in the dialog we have two buttons: datePicker and timePicker.
And that's not what I want to do - I want that the date and time picker appear at the same time.
So I think the two main problem will be:
- First make the time and date picker appear in the same dialog.
- And the second problem will be to change the appearance of time and date picker (the orange color).
The first problem was resolved by Bhavesh. Here is what I get:
The problem now is that I want to change all blue bar color to orange color.
I added android:calendarViewShown="false"
to remove the calendar in the right :) Thanks Bhavesh and I changed the theme to HOLO
Here is what I get:
You can download the code (that's the best I can do). You can download from here.
First make the time and date picker appear in the same dialog
Here i can help you some what: you can create a layout consisting of a DatePicker
and a TimePicker
in a LinearLayout
with the orientation set to vertical.
custom_dialog.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<DatePicker
android:id="@+id/datePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</DatePicker>
<TimePicker
android:id="@+id/timePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TimePicker>
</LinearLayout>
Then use this layout to create your dialog.
Dialog dialog = new Dialog(mContext);
dialog.setContentView(R.layout.custom_dialog);
dialog.setTitle("Custom Dialog");
To react to the user interacting with your TimePicker
, do something like this:
TimePicker tp = (TimePicker)dialog.findViewById(R.id.timepicker1);
tp.setOnTimeChangedListener(myOnTimechangedListener);
To get the values from the Date- and TimePicker when the user has finished setting them, add an OK button in your dialog, and then read the date and time values from the Date- and TimePicker when the user presses OK.
To make something that looks exactly as in your screen shots I recommend you to make all things custom with your own logic.
这篇关于日期和时间选择器对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!