1. Use the Android5.0 system to achieve the above effect using the Alertdialog
2. layout file: layout_dataselect
<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"> <DatePickerAndroid:layout_width= "Match_parent"Android:layout_height= "140DP"Android:id= "@+id/datepicker1"Android:calendarviewshown= "false"//causes the control to not appear in the calendar styleAndroid:datepickermode= "Spinner"//makes the control not use 5.0 new style /></LinearLayout>
2. Add a Button,textview to the main layout:
3.
Textview_datastart.setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (View v) {Alertdialog.builder LocalBuilder=NewAlertdialog.builder (wenjiansearch_activity. This); Localbuilder.settitle ("Select Time"). SetIcon (R.mipmap.ic_launcher); // FinalLinearLayout layout_alert= (LinearLayout) Getlayoutinflater (). Inflate (R.layout.layout_dataselect,NULL); Localbuilder.setview (Layout_alert); Localbuilder.setpositivebutton ("OK",NewDialoginterface.onclicklistener () { Public voidOnClick (Dialoginterface Paramanonymousdialoginterface,intparamanonymousint) {DatePicker Datepicker1=(DatePicker) Layout_alert.findviewbyid (r.id.datepicker1); inty=datepicker1.getyear (); intM=datepicker1.getmonth (+1); intD=Datepicker1.getdayofmonth (); System.out.println ("Y:" +y+ "M:" +m+ "D:" +d); Textview_datastart.settext (y+ "-" +m+ "-" +d); Get Time}}). Setnegativebutton ("Cancel",NewDialoginterface.onclicklistener () { Public voidOnClick (Dialoginterface Paramanonymousdialoginterface,intparamanonymousint) {}}). Create (). Show (); } });
Android Get DatePicker Date