Search code examples
androidandroid-dialogfragment

Android datepicker showing white view like dialog title in DialogFragment


How to remove that white view title coming in DialogFragment of DatePickerDialog

enter image description here

here is my DialogFragment code for reference :

public class DatePickerFrgDialog extends DialogFragment implements DatePickerDialog.OnDateSetListener {


    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        // Use the current date as the default date in the picker
        final Calendar c = Calendar.getInstance();
        int year = c.get(Calendar.YEAR);
        int month = c.get(Calendar.MONTH);
        int day = c.get(Calendar.DAY_OF_MONTH);
        DatePickerDialog dialog = new DatePickerDialog(getActivity(), this, year, month, day);

        // Create a new instance of DatePickerFrgDialog and return it
        return dialog;
    }

    @Override
    public void onDateSet(DatePicker view, int year, int month, int day) {


    }

If anyone came across this issue, than please share the solution.


Solution

  • try this code:

         @Override
        public Dialog onCreateDialog(Bundle savedInstanceState) {
          Dialog dialog = super.onCreateDialog(savedInstanceState);
    
          // request a dialog without the title
          dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE); 
          DatePickerDialog date_picker_dialog = new DatePickerDialog(getActivity(), this, year, month, day);
          date_picker_dialog.setTitle("");
          return dialog;
        }
    

    use :

    date_picker_dialog.setTitle("");
    

    or :

    date_picker_dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);