Material-components-android: [Alert Dialog] Padding added on bottom when the positive button's text is a little long

Created on 31 Aug 2020  路  5Comments  路  Source: material-components/material-components-android

Description: When creating a MaterialAlertDialog with the positive button's text a little long, padding gets added to the bottom of the dialog making it look out of place.

Screenshot_20200831-130148

Expected behavior: There should be no padding added.

Screenshot_20200831-133918

Source code:

MaterialAlertDialogBuilder(requireContext()).apply {
                    setTitle("Dialog title")
                    setMessage("Dialog body")
                    setPositiveButton("Agree and continue") { _, _ ->

                    }
                    setNeutralButton("No") { _, _ ->

                    }
                    show()                    
                }

Devices: OnePlus 6, Xiaomi Mi A2, Motorola G5 Plus
Android API versions: OnePlus 6 - 29, Xiaomi Mi A2 - 28, Motorola G5 Plus - 27
Material Library version: 1.2.0

bug

Most helpful comment

The issue can be replicated using an emulator with these specs:
https://www.gsmarena.com/oneplus_6-9109.php

Schermata 2020-09-01 alle 09 50 57

Schermata 2020-09-01 alle 09 51 49

It doesn't happen with the appcompat AlertDialog.Builder.

Schermata 2020-09-01 alle 09 53 19

All 5 comments

Hi, I'm not able to reproduce it, could you provide a sample app where the issue happens?

I have created a repository. I made it completely from scratch, only added Material components dependency in the gradle files and changed the app theme to inherit from MaterialComponents. Then I displayed the dialog.

The issue can be replicated using an emulator with these specs:
https://www.gsmarena.com/oneplus_6-9109.php

Schermata 2020-09-01 alle 09 50 57

Schermata 2020-09-01 alle 09 51 49

It doesn't happen with the appcompat AlertDialog.Builder.

Schermata 2020-09-01 alle 09 53 19

It does also appear on AlertDialog.Builder, just make the buttons labels larger and you can reproduce

image

AlertDialog.Builder(this)
                .setTitle("Discard draft?")
                .setMessage("This will permanently delete the current e-mail draft.")
                .setPositiveButton("Agree and continueeee") { _, _ -> }
                .setNeutralButton("No") { _, _ -> }
                .show()

And depending on the version, we have different behaviors:

v19 extra top padding on the button panel

image

v29 parent panel has extra height

image

When there is enough space for the buttons, the dialogs look like this:

v19

image

v29

image

Emulator used:

Galaxy Nexus
image

Good find! While I wasn't able to reproduce the same thing for the AlertDialog.Builder, this shows that there is inconsistency across all types of devices.

Was this page helpful?
0 / 5 - 0 ratings