[MaterialAlertDialogBuilder] Rounded corners for AlertDialog pre Android P
See original GitHub issueHi, thanks for the great work on Material Components.
Currently I’m facing a problem with MaterialAlertDialogBuilder. I’d like to style my AlertDialogs consistently across Android versions but setting a dialog corner radius is only possible from Android P onwards, since MaterialAlertDialogBuilder is using android.R.attr.dialogCornerRadius
.
If the dialogCornerRadius
attribute from AppCompat with R.attr.dialogCornerRadius
was used instead, it would be possible to define a corner radius for versions < P as well.
Right now, I work around this issue by supplying a custom drawable with rounded corners to the builder in setBackground
, which is a bit of a hassle.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:6 (1 by maintainers)
Top Results From Across the Web
How to make custom dialog with rounded corners in android
Create an XML file in drawable, say dialog_bg.xml : <?xml version="1.0" encoding="utf-8"?> ...
Read more >Dialogs - Material Design
... a dependency to the Material Components for Android library. For more information, go to the Getting started page. MaterialAlertDialogBuilder(context)
Read more >Android Dialog With Rounded Corners - ADocLib
Step 1 Create a new project in Android Studio go to File New P When user ... [MaterialAlertDialogBuilder] Rounded corners for AlertDialog pre...
Read more >How to make custom dialog with rounded corners in android?
Step 2 − Add the following code to res/layout/activity_main.xml. <?xml version="1.0" encoding= ...
Read more >Class Index - Android Developers
Draws an arrow on the edge given the radius of a circle. MaterialAlertDialogBuilder, An extension of AlertDialog.Builder for use with a Material ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@dominikgold So I’ve found a good, backwards compatible solution.
Create the following styles in your styles.xml like so:
When instantiating your MaterialAlertDialogBuilder, pass it the resource ID of the first style, like this:
new MaterialAlertDialogBuilder(getContext(), R.style.MaterialAlertDialog_Rounded)
And now you can easily change the corner radius with the ‘cornerSize’ attribute in the style. Hope this helps!
To have the change not affect the button shapes, you can do as follows:
and in your theme set
materialAlertDialogTheme
to yourThemeOverlay.MaterialAlertDialog.Rounded
to change all of your dialogs!