Search code examples
androidandroid-layoutandroid-alertdialogandroid-theme

Blank white space around Timepicker dialog


I am trying to create a time picker for my application.. and when setting the theme to Theme_DeviceDefault_Light_Dialog_NoActionBar_MinWidth

I am getting this output

enter image description here

I am getting a blank space around the dialog box

This is not happening when I am setting it to use the parent activity's theme which is appcompat.noactionbar

//not happening here
  return new TimePickerDialog(getActivity(),this, hour, minute,is24HourView );

Here is my timepicker code

    public class TimePickerFragment extends DialogFragment implements TimePickerDialog.OnTimeSetListener{

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState){
        //Use the current time as the default values for the time picker
        final Calendar c = Calendar.getInstance();
        int hour = c.get(Calendar.HOUR_OF_DAY);
        int minute = c.get(Calendar.MINUTE);

        boolean is24HourView=true;
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
        String formattedTime = sdf.format(c.getTime());
        Log.d("time", formattedTime);
        //Create and return a new instance of TimePickerDialog
//        return new TimePickerDialog(getActivity(),this, hour, minute,is24HourView );
      return new TimePickerDialog(getActivity(), android.R.style.Theme_DeviceDefault_Light_Dialog_NoActionBar_MinWidth,this, hour, minute,is24HourView );

    }

Solution

  • Change:

     android.R.style.Theme_DeviceDefault_Light_Dialog_NoActionBar_MinWidth
    

    with

     AlertDialog.THEME_DEVICE_DEFAULT_LIGHT
    

    or

     AlertDialog.THEME_HOLO_LIGHT
    

    It should work