Skip to content
Philipp Niedermayer edited this page May 21, 2023 · 11 revisions

Provided default styles

The library provides a number of default styles which use the app's primary/accent color by default and also support dark mode:

  1. @style/SimpleDialogTheme.AppCompat (with app theme Theme.AppCompat.DayNight)
  2. @style/SimpleDialogTheme.MaterialComponents (with app theme Theme.MaterialComponents.DayNight)
  3. @style/SimpleDialogTheme.Material3 (with app theme Theme.Material3.DayNight)
1. 2. 3.

Applying styles

Globally for all dialogs

You can specify a global theme for dialogs in your apps styles.xml.

  • Use the alertDialogTheme attribute to apply the theme to all dialogs
  • Or the simpleDialogTheme attribute to apply the theme only to SimpleDialogs
<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.Material3.DayNight">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorSecondary">@color/colorAccent</item>

        <!-- Using a default style -->
        <item name="alertDialogTheme">@style/SimpleDialogTheme.Material3</item>
        <item name="simpleDialogTheme">@style/SimpleDialogTheme.Material3</item>

        <!-- Or using a custom style -->
        <item name="simpleDialogTheme">@style/MyDialogTheme.Material3</item>

    </style>

    <!-- Customized themes which change the accent/primary color -->
    <style name="MyDialogTheme.AppCompat" parent="SimpleDialogTheme.AppCompat">
        <item name="colorAccent">@color/colorAccent</item>
        <item name="colorPrimary">@color/colorAccent</item>
    </style>
    <style name="MyDialogTheme.MaterialComponents" parent="SimpleDialogTheme.MaterialComponents">
        <item name="colorPrimary">@color/colorAccent</item>
    </style>
    <style name="MyDialogTheme.Material3" parent="SimpleDialogTheme.Material3">
        <item name="colorPrimary">@color/colorAccent</item>
    </style>

</resources>

Per dialog

You can set custom themes on a per-dialog-basis by using the theme(@StyleRes int theme) method:

SimpleDialog.build()
            // ...
            .theme(R.style.MyDialogTheme_MaterialComponents)
            .show(this);

Customizing styles

You can also define custom styles in styles.xml, see the test app's styles.xml for examples.