Theme change for alertDialog, depending on Android version

2

I'm developing an app, which uses some alertDialogs at certain times. my question is as follows, I would like to leave the subject of these alerts according to the Android version of the smartphone that will be run the app, ie, it "pick up" the definitions of customizations already from the android and transmit to the alert. I did not want to change through XML and leave a pattern, I want the pattern to be according to the version of the android on which the app is running. In this case, I am testing through a Moto X with Android 4.4.2 that has its black theme with blue, but alertDialog appears white with the black letters.

Thank you to all of you!

    
asked by anonymous 08.04.2015 / 15:09

1 answer

1

According to the documentation the Theme used by AlertDialog is determined internally and privately by Android.

If you create an AlertDialog using AlertDialog.Builder(context) it will be created with the Theme pre-defined (device default).

You can however change this Theme using the AlertDialog.Builder(context, theme) constructor where theme is one of the following constants:

  • THEME_DEVICE_DEFAULT_DARK - Uses the pre-defined theme with a black background.
  • THEME_DEVICE_DEFAULT_LIGHT - Uses the pre-defined theme with white background.
  • THEME_HOLO_DARK - Uses the HOLO theme with a black background.
  • THEME_HOLO_LIGHT - Uses the HOLO theme with a white background.
  • THEME_TRADITIONAL - Uses the traditional theme (pre-Holo).

Answering the question:

To create an AlertDialog that uses the Theme pre-set according to Android version use:

AlertDialog.Builder(context)
    
08.04.2015 / 15:55