I want to use digital datepicker dialog and timepicker dialog

Viewed 9672

I want to use digital datepicker dialog and timepicker dialog, I have writte the code and my picker dialogs are working but I want them in another format.

Currently my time picker and date picker dialog are in this format: enter image description here enter image description here

I want them like this: enter image description here

Here is my code:

    public void onClick(View v) {
            int id = v.getId();
            switch(id){

                case R.id.linearDate: {

                    DatePickerDialog dp = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
                        @Override
                        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                            mDatetext.setText(dayOfMonth+"-"+monthOfYear+"-"+year);

                        }
                    },year,month,day);
                    dp.show();
                }break;

                case R.id.linearTime: {

                    TimePickerDialog Tp = new TimePickerDialog(this, new TimePickerDialog.OnTimeSetListener() {
                        @Override
                        public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                            mTimetext.setText(hourOfDay+ ":" +minute);

                        }
                    },hour,min,false);
                    Tp.show();
                }break;
                case R.id.linearPlace:{ startActivityForResult(new Intent(this,Location.class),CITY);

                }break;
            }
        }
6 Answers

Might be Helpfull

int mHour,mMinute;
TimePickerDialog Tp = new TimePickerDialog(getContext(),R.style.abirStyle, new TimePickerDialog.OnTimeSetListener() {
                    @Override
                    public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                        //mTimetext.setText(hourOfDay+ ":" +minute);

                    }
                },mHour,mMinute,false);
                Tp.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                Tp.show();

in Style

<style name="abirStyle" parent="@android:style/Theme.Holo.Light.Dialog.NoActionBar">
    <item name="android:textColor">@color/colorPrimary</item>
    <item name="android:background">@null</item>
    <item name="android:textColorPrimary">@color/colorPrimary</item>
</style>

simply add this line to your TimePicker on layout file:

android:timePickerMode="spinner"

that's it.

Related