android studio日期选择器不在对话框上

时间:2017-06-16 06:20:45

标签: android datepicker

如何创建不在对话框中的日期时间选择器。你们有个主意吗?像这样Redux's docs

任何建议都可能有所帮助。谢谢!

3 个答案:

答案 0 :(得分:0)

您可以在xml文件中添加以下行。

<DatePicker
   android:id="@+id/datePicker"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:calendarViewShown="false"/>

答案 1 :(得分:0)

试试这个

<DatePicker xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/date_picker"
android:layout_width="fill_parent"
android:spinnersShown="true"
android:calendarViewShown="false"
android:layout_height="fill_parent"/>

public class DatePickerFragment extends DialogFragment {

private OnDateChosenListener mListener;

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final DatePicker datePicker = (DatePicker) getActivity().getLayoutInflater().
            inflate(R.layout.dialog_date_picker, null);
    //Set an initial date for the picker
    Calendar c = Calendar.getInstance();
    int year = c.get(Calendar.YEAR);
    int month = c.get(Calendar.MONTH);
    int day = c.get(Calendar.DAY_OF_MONTH);
    //Set the date now
    datePicker.updateDate(year, month, day);

    //create the dialog
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    //set the title
    builder.setTitle(getString(R.string.date_picker_title))
            .setView(datePicker)
            .setPositiveButton(R.string.picker_confirmation, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // do some stuff with the date
                }
            });
    return builder.create();
}


// from an Activity...
DatePickerFragment dialog = new DatePickerFragment();
dialog.show(getFragmentManager(), "datePicker");

有关详细信息,请点击此链接Datepicker Android

答案 2 :(得分:0)

<DatePicker
    android:id="@+id/datePicker"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:calendarViewShown="false"
    android:datePickerMode="spinner"
    android:spinnersShown="true" />