Java 如何在Android的AlertDialog中设置主题

Java 如何在Android的AlertDialog中设置主题,java,android,eclipse,Java,Android,Eclipse,我已经找了一个半小时了,但是我想不出来。我不想设置自定义主题。我想为AlertDialog设置一个内置在android中的主题 根据d.android.com,我可以做到: public AlertDialog.Builder (Context context) 还是这个 public AlertDialog.Builder (Context context, int theme) 所以我这么做了,效果非常好: AlertDialog action_btn = new AlertDialog

我已经找了一个半小时了,但是我想不出来。我不想设置自定义主题。我想为AlertDialog设置一个内置在android中的主题

根据d.android.com,我可以做到:

public AlertDialog.Builder (Context context)
还是这个

public AlertDialog.Builder (Context context, int theme)
所以我这么做了,效果非常好:

AlertDialog action_btn = new AlertDialog.Builder(MyActivity.this).create();
但是,当我需要添加一个主题时,我从eclipse中得到一个错误:

AlertDialog action_btn = new AlertDialog.Builder(MyActivity.this, AlertDialog.THEME_TRADITIONAL).create();
我还是一个编程新手,如果有人能帮我设置一个主题,我将不胜感激

我还有一个额外的问题:


我不能只让
AlertDialog()
工作,要使它工作,我需要键入
AlertDialog.Builder()
,但在开发者网站上,它们似乎都有相同的方法和构造函数。有什么区别/为什么AlertDialog()不能正常工作?

AlertDialog.Builder的主题仅适用于Android 3.0及更高版本(API级别11)。似乎您已经在项目设置中设置了较早的Android版本

Android引用显示了所有构造函数和方法的API级别。您甚至可以设置一个过滤器,只显示API级别可用的方法


将主题包装到上下文中,这从API级别1开始提供

Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(
    this,android.R.style.Theme_DeviceDefault_Light_Dialog));

啊。真不敢相信。我看到它说“自API级别!”所以我认为一切都是有效的,但如果你向下滚动页面的1/3,它确实说它只在“API级别11”中有效。谢谢这是一个非常简单的解决方案。如果您想在使用低于API 11的API时寻找对话框样式的解决方案,请看这里