question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[MaterialAlertDialog] Extra space below buttons if they fill the whole width

See original GitHub issue

Description: Whenever negative and positive buttons of a dialog are close to being stacked vertically, the MaterialAlertDialog adds some extra space below them:

This happens with the following patch applied to the codebase:

Index: material-theme-builder/src/main/java/io/material/materialthemebuilder/ui/component/ComponentViewHolder.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- material-theme-builder/src/main/java/io/material/materialthemebuilder/ui/component/ComponentViewHolder.kt	(revision b58d3481c3619ca1e944f8c69e53418383489d2e)
+++ material-theme-builder/src/main/java/io/material/materialthemebuilder/ui/component/ComponentViewHolder.kt	(date 1573147313000)
@@ -159,8 +159,8 @@
       MaterialAlertDialogBuilder(view.context)
         .setTitle(R.string.text_headline_6)
         .setMessage(R.string.lorem_ipsum)
-        .setPositiveButton(R.string.text_button, null)
-        .setNegativeButton(R.string.text_button, null)
+        .setPositiveButton("longer button here", null)
+        .setNegativeButton("button", null)
         .show()
     }
   }

Expected behavior: There should be no extra space below the buttons.

Android API version: 28

Material Library version: 1.1.0-beta01

Device: Nexus 4 Emulator image

All OS settings are default including the font size.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:14
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
mknrcommented, Apr 20, 2021

better simpler.

 MaterialAlertDialogBuilder(context)
    .setTitle("Title")
    .setMessage("Message")
    .setPositiveButton("Looooooong Text") { _, _ -> }
    .setNegativeButton(android.R.string.cancel) { _, _ -> }
    .create()
    .apply { // add this block
        window?.let {
            it.attributes = it.attributes?.also {
                it.width = WindowManager.LayoutParams.MATCH_PARENT
                it.height = WindowManager.LayoutParams.WRAP_CONTENT
            }
        }
    }
0reactions
drchencommented, Oct 6, 2021

I’ll close the issue since it’s been fixed on AppCompat. : )

Read more comments on GitHub >

github_iconTop Results From Across the Web

android - How to make an alert dialog fill 90% of screen size?
This answer was very helpful for the scenario of trying to recreate a dialog in onCreate after device rotation. In this case, we...
Read more >
Dialogs - Android Developers
A dialog is a small window that prompts the user to make a decision or enter additional information. A dialog does not fill...
Read more >
Dialogs - Material Design
When there are three or more actions with long text labels in a Material dialog, ... Dialog with two full width text buttons,...
Read more >
How To Set Margin For Buttons Materialalertdialog In Android
Ask questions[MaterialAlertDialog ] Extra space below buttons if they fill the whole width. Description: Whenever negative and positive buttons of a dialog are....
Read more >
Android Material Components - MaterialAlertDialog
If you have any suggestions for improvements, please let us know by clicking the “report an issue“ button at the bottom of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found