0

I'm trying to show DatePickerDialog and TimePickerDialog in my Activity using the following code:

    private void showDatePickerDialog(DatePickerDialog.OnDateSetListener listener) {

        Calendar c = Calendar.getInstance();

        DatePickerDialog dialog = new DatePickerDialog(
                this,
                listener,
                c.get(Calendar.YEAR),
                c.get(Calendar.MONTH),
                c.get(Calendar.DAY_OF_MONTH)
        );

        dialog.show();

    }

My activity extends from AppCompatActivity and I have the following dependencies in my gradle file:

compile 'com.android.support:support-v4:25.4.0'
compile 'com.android.support:appcompat-v7:25.4.0'
compile 'com.android.support:design:25.4.0'

The problem is that the dialogs do not have proper padding:

DatePickerDialog

TimePickerDialog

I'm using a Samsung Galaxy J1 with API 22 for testing, my project's minSdkVersion is 16 and targetSdkVersion 25. Any help would be appreciated.

P.S. The same thing happens with Toast messages:

Toast messages

Edit: I'm using the following Theme:

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/primary</item>
        <item name="colorPrimaryDark">@color/primary_dark</item>
        <item name="colorAccent">@color/accent</item>
        <item name="android:fitsSystemWindows">true</item>
        <item name="android:windowAnimationStyle">@style/CustomActivityAnimation</item>
    </style>
9
  • Did you try to update your targetSdk to 27 and the support dependencies to 27.0.2?
    – chrjs
    Dec 5, 2017 at 12:41
  • @chrjs unfortunately no, that didn't solve it
    – lpassadore
    Dec 5, 2017 at 12:51
  • What theme you are using . Post in question . Dec 5, 2017 at 12:53
  • @ADM edited the question including the Theme
    – lpassadore
    Dec 5, 2017 at 12:57
  • try after remove fitsSystemWindows once. Dec 5, 2017 at 13:02

1 Answer 1

0

Change your style as for above Api 21 in v21\styles.xml.

 <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primary_dark</item>
    <item name="colorAccent">@color/accent</item>
    <item name="android:windowAnimationStyle">@style/CustomActivityAnimation</item>
</style>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.