So the problem is very simple:
I have integrated a DatePicker
in my application.
Not as a DialogDatePicker
but as a View component (more pr
Answering to your update
Change
android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen"
to
android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen"
You have to use the Holo theme.
So, your theme should look like this:
<style name="AppTheme" parent="@android:style/Theme.Holo">
...
</style>
Here is a snippet for calling device's default Date And Time Picker
date_time_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
<DatePicker
android:id="@+id/datePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:calendarViewShown="false" > <!-- style="@style/date_picker_style" -->
</DatePicker>
<TimePicker
android:id="@+id/timePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TimePicker>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/dialogCancel"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel" />
<Button
android:id="@+id/dialogSet"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Set" />
</LinearLayout>
</LinearLayout>
</ScrollView>
Put this method in your class and call it using showDateAndTimePicker();
private void showDateAndTimePicker() {
final Dialog dialog = new Dialog(this,
android.R.style.Theme_DeviceDefault_Dialog);
dialog.setContentView(R.layout.date_time_layout);
dialog.setCancelable(false);
dialog.setTitle("Select Date and Time");
Button set = (Button) dialog.findViewById(R.id.dialogSet);
Button cancel = (Button) dialog.findViewById(R.id.dialogCancel);
final DatePicker dtp = (DatePicker) dialog
.findViewById(R.id.datePicker1);
final TimePicker tp = (TimePicker) dialog
.findViewById(R.id.timePicker1);
set.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Handle Set button
dialog.dismiss();
}
});
cancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//Handle Cancel button
dialog.dismiss();
}
});
dialog.show();
}
Set your android:targetSdkVersion
to be 11 or higher. Here is a sample application demonstrating this.
UPDATE
First, your original DatePicker
screenshot is from a dark theme (e.g., Theme.Holo
), whereas your second screenshot is from a light theme (e.g., Theme.Holo.Light
).
Second, the DatePicker
documentation has the following opening paragraph:
This class is a widget for selecting a date. The date can be selected by a year, month, and day spinners or a CalendarView. The set of spinners and the calendar view are automatically synchronized. The client can customize whether only the spinners, or only the calendar view, or both to be displayed. Also the minimal and maximal date from which dates to be selected can be customized.
You can get rid of the CalendarView
via android:calendarViewShown
(or setCalendarViewShown()
). When you try that, you will find that your year spinner will appear once the CalendarView
is gone.