Skip to content
Eltos edited this page Jul 23, 2022 · 11 revisions

Provided default styles

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

@style/SimpleDialogTheme @style/SimpleDialogTheme.Material @style/SimpleDialogTheme.Material3

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.MaterialComponents.DayNight">
        <!-- Using a default style -->
        <item name="alertDialogTheme">@style/SimpleDialogTheme</item>
        <item name="simpleDialogTheme">@style/SimpleDialogTheme.Material</item>

        <!-- Or using a custom style -->
        <item name="simpleDialogTheme">@style/MyCustomDialogTheme</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.MyCustomDialogTheme)
            .show(this);

Custom styles

You can also define custom styles in styles.xml, for example:

<resources>
    <style name="MyCustomDialogTheme" parent="SimpleDialogTheme">
        <item name="android:colorBackground">#282828</item>
        <item name="colorPrimary">#a000ff</item>
        <item name="colorSecondary">#d50000</item>
        <item name="android:textColorPrimary">#33691e</item>
        <item name="checkboxStyle">@style/MyCheckBoxStyle</item>
        <item name="textInputStyle">@style/MyTextInputStyle</item>
    </style>
    <style name="MyCheckBoxStyle" parent="@style/Widget.AppCompat.CompoundButton.CheckBox">
        <item name="android:textColor">#64b5f6</item>
    </style>
    <style name="MyTextInputStyle" parent="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu">
        <item name="endIconMode">none</item>
    </style>

    <!-- When customizing the theme for a SimpleImageDialog you must either
         inherit from "ImageDialogTheme" or specify the two attributes as shown below -->

    <style name="MyCustomImageDialogThemeA" parent="ImageDialogTheme">
        <!-- ... -->
    </style>
    <style name="MyCustomImageDialogThemeB" parent="MyCustomDialogTheme">
        <item name="android:windowMinWidthMinor">@null</item>
        <item name="android:windowMinWidthMajor">@null</item>
        <!-- ... -->
    </style>
</resources>