19

How do you get the black themed Dialog in android like shown on the android guide http://developer.android.com/guide/topics/ui/dialogs.html

I took a screen shot. Whenever I use Alert Dialog, I get the dialog on the left, I want the one on the right.

enter image description here

Akshat Agarwal
  • 2,837
  • 5
  • 29
  • 49

4 Answers4

38

It's simple for API 11 onwards:

AlertDialog.Builder alert = new AlertDialog.Builder(context, AlertDialog.THEME_DEVICE_DEFAULT_DARK);

The field THEME_DEVICE_DEFAULT_DARK was added in API 14 so if you are targeting before then, just use the numeric value, thus:

AlertDialog.Builder alert = new AlertDialog.Builder(context, 4);

The different constants you can use, and their values are shown here. On pre API 14 you will still get the white alert though.

----------------------------------------------------------------UPDATE--------------------------------------------------------

AlertDialog.THEME_DEVICE_DEFAULT_DARK is depreciated,

Below is the updated code:

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this, android.R.style.Theme_DeviceDefault_Light_Dialog_Alert);

You can choose different themes instead of this android.R.style.Theme_DeviceDefault_Light_Dialog_Alert

Abdul Aleem
  • 679
  • 8
  • 31
Steve Waring
  • 2,882
  • 2
  • 32
  • 37
6

res/values/styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
        <style name="default_activity_theme" parent="@android:style/Theme.Holo"/>
</resources>

AndroidManifest.xml

<activity android:name=".ActivityMain"
          android:theme="@style/default_activity_theme"/>
resource8218
  • 1,445
  • 1
  • 20
  • 33
1

If you don't want to change your Activity's theme, you can extend AlertDialog and supply the Theme.Holo in its contructor: AlertDialog(Context context, int theme).

Tim S. Van Haren
  • 8,861
  • 2
  • 30
  • 34
Nitin Sethi
  • 1,416
  • 1
  • 11
  • 19
0

In case of using DialogFragment to implement customised dialog, set the theme in onCreate() method like this:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState)
    setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Holo_Dialog)
}
zhezha
  • 61
  • 5