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.

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.

从 API 11 开始,这很简单:
AlertDialog.Builder alert = new AlertDialog.Builder(context, AlertDialog.THEME_DEVICE_DEFAULT_DARK);
该字段THEME_DEVICE_DEFAULT_DARK是在 API 14 中添加的,因此如果您在此之前定位,只需使用数值,因此:
AlertDialog.Builder alert = new AlertDialog.Builder(context, 4);
您可以使用的不同常量及其值显示在此处。不过,在 API 14 之前,您仍然会收到白色警报。
-------------------------------------------------- --------------更新----------------------------------- ---------------------
AlertDialog.THEME_DEVICE_DEFAULT_DARK已贬值,
以下是更新后的代码:
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this, android.R.style.Theme_DeviceDefault_Light_Dialog_Alert);
您可以选择不同的主题而不是这个android.R.style.Theme_DeviceDefault_Light_Dialog_Alert
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"/>
如果你不想改变你Activity的主题,你可以在它的构造函数中扩展AlertDialog和提供Theme.Holo: AlertDialog(Context context, int theme)。
如果DialogFragment用于实现自定义对话框,请在onCreate()方法中设置主题,如下所示:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState)
setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Holo_Dialog)
}