Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove extra space space in DatePickerDialog (seen on Android M & N)?

I'm seeing an extra space on the right of the DatePickerDialog, only on Android M & N builds. It's not observed on L based build. Here's the screenshot:

Has anyone faced this problem ?

This is the implementation of DatePickerFragment:

public class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {

    public static DatePickerFragment newInstance(int day, int month, int year)
    {
        DatePickerFragment frag = new DatePickerFragment();
        Bundle args = new Bundle();
        args.putInt("day", day);
        args.putInt("month", month);
        args.putInt("year", year);
        frag.setArguments(args);
        return frag;
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState)
    {
        int year = getArguments().getInt("year");
        int month = getArguments().getInt("month");
        int day = getArguments().getInt("day");
        DatePickerDialog datePickerDialog =new DatePickerDialog(getActivity(), this, year, month, day);
        datePickerDialog.getDatePicker().setMinDate(System.currentTimeMillis() - 1000);
        return datePickerDialog;
    }

    @Override
    public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth)
    {
        try
        {
            DatePickerDialogListener listener = (DatePickerDialogListener)getActivity();
            listener.onFinishDatePickDialog(year, monthOfYear + 1, dayOfMonth);
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
    }

    // 1. Defines the listener interface with a method passing back data result.
    public interface DatePickerDialogListener {
        void onFinishDatePickDialog(int year, int monthOfYear, int dayOfMonth);
    }

}

And here's the style sheet which has a component for android:datePickerDialogTheme

    <style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowContentTransitions">true</item>
        <item name="colorControlNormal">@color/colorAccent</item>
        <item name="colorControlActivated">@color/colorAccent</item>
        <item name="colorControlHighlight">@color/colorAccent</item>
        <item name="textColorError">@android:color/holo_red_dark</item>
        <item name="android:timePickerDialogTheme">@style/AlertDialogCustom</item>
        <item name="android:datePickerDialogTheme">@style/AlertDialogCustom</item>
        <item name="android:alertDialogTheme">@style/AlertDialogCustom</item>
    </style>

    <style name="AlertDialogCustom" parent="android:Theme.Material.Light.Dialog.Alert">
        <item name="android:colorPrimary">@color/colorPrimary</item>
        <item name="android:colorAccent">@color/colorAccent</item>
    </style>

NOTE: The issue is not seen if I don't use the styles to modify color.

like image 285
Monu Surana Avatar asked Sep 11 '16 01:09

Monu Surana


1 Answers

Do not use Theme.AppCompat.Light.Dialog.Alert, simply use Theme.AppCompat.Light.Dialog is ok. As you look inside,

<style name="Base.ThemeOverlay.AppCompat.Dialog.Alert"> <item name="android:windowMinWidthMajor">@diem/abc_dialog_min_width_major</item> <item name="andorid:windowMinWidthMinor">@dimen/abc_dialog_min_width_minor</item> </style>

There is additional size amendment on the style, which turns out is undesired.

like image 190
Keith Ma Avatar answered Sep 30 '22 12:09

Keith Ma