MaterialComponents theme alert dialog buttons

material design alert dialog android github
android-alertdialog button style
android dialog theme
material components-android
theme appcompat light dialog alert
theme materialcomponents button background
confirmation dialog android
materialalertdialogbuilder gradle

Recently I switched from support library to

But now I have a problem, in this pages there's a note

Note: Using a Material Components theme enables a custom view inflater which replaces default components with their Material counterparts. Currently, this only replaces Button XML components with MaterialButton.

And the theme I am using


does exactly what it says in that note, it replaces AlertDialog Buttons to MaterialButtons but the problem is that by default MaterialButtons are colored background and now the buttons looks like this:

How can I make them borderless and backgroundless again?

PS I am using alert builder to create alert dialogs:

I figured out what was causing this problem. I need to use different AlertDialog class:

When I switched to this everything started working as expected. Here's where I found the solution:

AlertDialog has filled buttons when using "Theme.MaterialComponents.Light.​NoActionBar" #199. Closed. bjarn opened this issue on Sep 19,  PS I am using alert builder to create alert dialogs: android material-design android-alertdialog android-styles material-components-android

When using and you can customize each button in the buttonBar by using Widget.MaterialComponents.Button.TextButton as parent.

val builder: AlertDialog.Builder = AlertDialog.Builder(ContextThemeWrapper(context,

Use the default layout or add a custom by builder.setView(R.layout.my_dialog)

In your styles:

<style name="AlertDialogTheme" parent="Theme.MaterialComponents.Light.Dialog.Alert">
    <item name="buttonBarPositiveButtonStyle">@style/Alert.Button.Positive</item>
    <item name="buttonBarNegativeButtonStyle">@style/Alert.Button.Neutral</item>
    <item name="buttonBarNeutralButtonStyle">@style/Alert.Button.Neutral</item>

<style name="Alert.Button.Positive" parent="Widget.MaterialComponents.Button.TextButton">
    <item name="backgroundTint">@color/transparent</item>
    <item name="rippleColor">@color/colorAccent</item>
    <item name="android:textColor">@color/colorPrimary</item>
    <item name="android:textSize">14sp</item>
    <item name="android:textAllCaps">false</item>

<style name="Alert.Button.Neutral" parent="Widget.MaterialComponents.Button.TextButton">
    <item name="backgroundTint">@color/transparent</item>
    <item name="rippleColor">@color/colorAccent</item>
    <item name="android:textColor">@color/gray_dark</item>
    <item name="android:textSize">14sp</item>

Setting up a Material Components theme for Android Alert dialog: The simplest of dialogs, despite the name. Used to interrupt a user with urgent Characterized by a title, optional supporting text and action buttons. Currently, this only replaces Button XML components with MaterialButton. And the theme I am using Theme.MaterialComponents.Light.NoActionBar [&hellip;] Sign Up

If you are using the Material Components library the best way to have an AlertDialog is to use the MaterialAlertDialogBuilder.

new MaterialAlertDialogBuilder(context)
            .setMessage("Lorem ipsum dolor ....")
            .setPositiveButton("Ok", /* listener = */ null)
            .setNegativeButton("Cancel", /* listener = */ null)

It is the default result:

Create a custom alert dialog theme that inherited from ThemeOverlay. parent="​Widget.MaterialComponents.Button.TextButton.Dialog"> Hi, I just noticed that AlertDialog has filled buttons with the "Theme.MaterialComponents.Light.NoActionBar" theme. When I use the default "Theme.AppCompat.Light.NoActionBar" theme, AlertDialog has simple text buttons as expected.

Found another solution for this with using MaterialComponents here:

<style name="Theme.Custom.Material.Alert.Dialog.Light" parent="Theme.MaterialComponents.Light.Dialog.Alert">
    <item name="materialButtonStyle">@style/Widget.AppCompat.Button.Borderless</item>

<style name="Theme.Custom.Material.Base.Light" parent="Theme.MaterialComponents.Light.NoActionBar">
    <item name="android:dialogTheme">@style/Theme.Custom.Material.Alert.Dialog.Light</item>
    <item name="android:alertDialogTheme">@style/Theme.Custom.Material.Alert.Dialog.Light</item>

Though it is still not "intended behavior" to me.

In this tutorial, we'll be customizing Dialogs using Material Theme in our. Button​.Neutral</item> </style> <style name="Alert.Button.Positive" parent="Widget. Styled Buttons. We can style the buttons of MaterialAlertDialog since they are just MaterialButtons. Setting outline button/borderless button, ripple effects etc. Let’s see an example: <style name="AlertDialogTheme"> <item name="buttonBarPositiveButtonStyle">@style/Alert.Button.Positive</item> <item name="buttonBarNeutralButtonStyle">@style/Alert.Button.Neutral</item> </style> <style name="Alert.Button.Positive" parent="Widget.MaterialComponents.Button.TextButton"> <item

First, it's better to use use MaterialAlertDialog if you are using Material Theme.

            .setPositiveButton(R.string.logout_alert_positive) { _, _ -> activity?.logout() }
            .setNegativeButton(R.string.never_mind, null)


This is the layout.xml of the MaterialAlertDialog actions. As you can see there are 3 buttons and each has their own styles. So, here is how you can change them.

Step 1: Tell Android that you want to alter the default MaterialAlertDialog theme.

<style name="Base.AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
    <item name="materialAlertDialogTheme">@style/AlertDialog</item>

Step 2: Tell Android that you want to alter a specific button style. buttonBarNeutralButtonStyle, buttonBarNegativeButtonStyle or buttonBarPositiveButtonStyle

<style name="AlertDialog" parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog">
    <item name="buttonBarNegativeButtonStyle">@style/NegativeButtonStyle</item>

Step 3: Define your custom style

<style name="NegativeButtonStyle" parent="Widget.MaterialComponents.Button.TextButton">
    <item name="android:textColor">#FF0000</item>

And the theme I am using. Theme.MaterialComponents.Light.NoActionBar. does exactly what it says in that note, it replaces AlertDialog Buttons  There are four types of dialogs: 1. Alert dialog, 2. Simple dialog, 3. Confirmation dialog, 4. Full-screen dialog. Dialogs. A dialog is a type of modal window that appears in front of app content to provide critical information or ask for a decision.

I figured out what was causing this problem. I need to use different AlertDialog class: When I switched to  When scrolling is required, the dialog title is pinned at the top, with buttons pinned at the bottom. This ensures selected content remains visible alongside the title and buttons, even upon scroll. Dialogs don’t scroll with elements outside of the dialog, such as the background.

IDEA says that API 21+ is required to use colorAccent on Base.Theme.AppCompat.Light.Dialog.Alert using '' – Felipe Andrade Nov 24 '16 at 12:53

I have many alert dialogs in my app. It is a default layout but I am adding positive and negative buttons to the dialog. So the buttons get the default text color of Android 5 (green). I tried to c

  • You can use Bridge theme if you want AppCompat theme contents with some new Material UI styles, it can solve your problem, refer my this answer :
  • I migrated my code to androidx using the Android Studio's 'Migrate to AndroidX' option/feature but this library was not updated to AndroidX automatically. This issue for me was resolved when I updated the import manually as the answer suggests
  • You save me! Thanks!
  • This is what I was looking for when trying to style my dialogs. All answers I found were not using AndroidX.
  • I'm just not sure why you're setting up textAllCaps to false. I usually see it set to true on dialogs (the only exception was a Material Design example from google called Crane)
  • @LeonardoSibela Yea, default behaviour sets all buttons to textAllCaps=true, updated
  • I wish I could upvote this 50 times. I spent like two hours trying to just color stupid dialogs. Note that you should also use MaterialAlertDialogBuilder instead.
  • @gMale 's comment saved time for me.
  • yes but it's still in alpha no ?