Reputation: 2847
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.
Upvotes: 19
Views: 33420
Reputation: 81
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)
}
Upvotes: 0
Reputation: 3023
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
Upvotes: 38
Reputation: 1336
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)
.
Upvotes: 1
Reputation: 1485
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"/>
Upvotes: 6