How to change the style of a DatePicker in android?

后端 未结 7 1489
孤街浪徒
孤街浪徒 2020-11-30 19:29

I want to change the default color of the date/time picker dialog in Android, so that it should match my app\'s theme. I searched for the solution on Google, but I couldn\'t

7条回答
  •  遥遥无期
    2020-11-30 19:34

    Create a new style

    
    

    Then initialize the dialog

    Calendar mCalendar = new GregorianCalendar();
    mCalendar.setTime(new Date());
    
    new DatePickerDialog(mContext, R.style.my_dialog_theme, new DatePickerDialog.OnDateSetListener() {
        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            //do something with the date
        }
    }, mCalendar.get(Calendar.YEAR), mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH)).show();
    

    Result:

提交回复
热议问题