Change of theme of alertDialog as per Android version

Asked

Viewed 388 times

2

I’m developing an app, which uses some alertDialogs at certain times. my question is the following, I would like to leave the theme of these Alerts according to the Android version of the smartphone that will run the app, IE, it "pick up" the customizations settings already from android and stream to Alert. I didn’t want to change through XML and leave a pattern, I want the default to be according to the android version on which the app is running. In this case, I’m performing the tests through a Moto X with Android 4.4.2 that has its theme black with blue, but the alertDialog appears white with black letters.

I appreciate all your help !

1 answer

1


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

If you create a Alertdialog using AlertDialog.Builder(context) he will be created with the Theme preset(default device).

However it is possible to change this Theme using the builder AlertDialog.Builder(context, theme) where Theme is one of the following constants:

  • THEME_DEVICE_DEFAULT_DARK - Use default Theme with black background.
  • THEME_DEVICE_DEFAULT_LIGHT - Use default Theme with white background.
  • THEME_HOLO_DARK - Use HOLO Theme with black background.
  • THEME_HOLO_LIGHT - Use Theme HOLO with white background.
  • THEME_TRADITIONAL - Use traditional Theme(pre-Holo).

Answering the question:

To create a Alertdialog use the Theme preset set according to android version use:

AlertDialog.Builder(context)
  • Strange, I will do some tests on other devices, but is already AlertDialog.Builder(context). If I use Theme it will be a pattern already for any device isn’t it? Well, I’ll see what I can, thank you !

Browser other questions tagged

You are not signed in. Login or sign up in order to post.