Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the default alert Dialog on android have a black theme

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

like image 676
Akshat Agarwal Avatar asked Oct 22 '13 15:10

Akshat Agarwal


People also ask

How do I customize alert dialog?

Add custom_layout. xml in that activity in which you want to show custom alert dialog here it is added in MainActivity. java.


2 Answers

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"/>
like image 22
resource8218 Avatar answered Oct 27 '22 20:10

resource8218


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

like image 62
Steve Waring Avatar answered Oct 27 '22 21:10

Steve Waring