How can i change date picker done background and selector background in android?

1.8k Views Asked by At

In android date picker i need to change the done button background.

Code:

 private void showDateDialog() 
{
    Calendar c = Calendar.getInstance();
    int year = c.get(Calendar.YEAR);
    int monthOfYear = c.get(Calendar.MONTH) + 1;
    int dayOfMonth = c.get(Calendar.DAY_OF_MONTH);

    String currentdate = year+"";
    if(monthOfYear<10)
        currentdate += "0";
    currentdate += (monthOfYear);
    if(dayOfMonth<10)
        currentdate += "0";             
    currentdate += dayOfMonth;

    currentDate = Integer.parseInt(currentdate);

    DatePickerDialog datePickerDialog = new DatePickerDialog(SelectEvent.this, new OnDateSetListener() 
    {
        @Override
        public void onDateSet(DatePicker view, int _year, int _monthOfYear,
                int _dayOfMonth) 
        {
            String date = _year+"";
            if(_monthOfYear+1<10)
                date += "0";
            date += (_monthOfYear+1);
            if(_dayOfMonth<10)
                date += "0";                
            date += _dayOfMonth;

            selectedDate = Integer.parseInt(date);
            DOB = date;

            if(selectedDate >= currentDate)
                eventdate.setText(_dayOfMonth+"/"+(_monthOfYear+1)+"/"+_year);
            else
            {
                eventdate.setText("");
                showDialog("Please Select Event Date");
                //Toast.makeText(context, "Please Select Event Date", Toast.LENGTH_SHORT).show();
            }
        }
    }, year, monthOfYear-1, dayOfMonth);

    datePickerDialog.setButton(DatePickerDialog.BUTTON_POSITIVE, "DONE", datePickerDialog);
    datePickerDialog.show();
}

If i use this code i got only default datepicker and simply Done changed to DONE. But i want that date picker to be https://drive.google.com/file/d/0B2NGqFM-F0bNWGl2VG93OUJpaWM/edit?usp=sharing

Please give some ideas and suggestion how can i change that colors in android. In this site i searched but i didn't get.

Thanks&Regards Shankar

2

There are 2 best solutions below

0
On
datePickerDialog.show();
    datePickerDialog.getButton(DatePickerDialog.BUTTON_POSITIVE).setBackgroundDrawable(getResources().getDrawable(R.drawable.browse_background));
    datePickerDialog.getButton(DatePickerDialog.BUTTON_POSITIVE).setTextSize(30);
    datePickerDialog.getButton(DatePickerDialog.BUTTON_POSITIVE).setTypeface(typeface);
    datePickerDialog.getButton(DatePickerDialog.BUTTON_POSITIVE).setTextColor(getResources().getColor(R.color.white));
    datePickerDialog.getButton(DatePickerDialog.BUTTON_POSITIVE).setText("DONE");

use this working fine.

8
On

Try the following code. It gets the button from the dialog and sets a custom drawable background on it.

Button b = datePickerDialog.getButton(DialogInterface.BUTTON_POSITIVE);
if(b != null) {
    b.setBackgroundDrawable(getResources().getDrawable(R.drawable.your_custom_background_here));
}