-
-
Notifications
You must be signed in to change notification settings - Fork 18
Styles
Philipp Niedermayer edited this page May 21, 2023
·
11 revisions
The library provides a number of default styles which use the app's primary/accent color by default and also support dark mode:
-
@style/SimpleDialogTheme.AppCompat
(with app themeTheme.AppCompat.DayNight
) -
@style/SimpleDialogTheme.MaterialComponents
(with app themeTheme.MaterialComponents.DayNight
) -
@style/SimpleDialogTheme.Material3
(with app themeTheme.Material3.DayNight
)
1. | 2. | 3. |
---|---|---|
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>
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);
You can also define custom styles in styles.xml
, see the test app's styles.xml
for examples.
Javadoc API
Screenshot gallery
Styling dialogs with themes
Fullscreen dialogs
SimpleDialog
CustomViewDialog
CustomListDialog
SimpleCheckDialog
SimpleColorDialog
SimpleColorWheelDialog
SimpleDateDialog
SimpleEMailDialog
SimpleFormDialog
SimpleImageDialog
SimpleInputDialog
SimpleListDialog
SimplePinDialog
SimpleProgressDialog
SimpleTimeDialog