所以我一直在寻找大约一个半小时,但我无法弄清楚。我不想设置自定义主题。我想为 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()
不能正常工作?
最佳答案
将主题包装到上下文中,这从 API 级别 1 开始可用。
Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(
this,android.R.style.Theme_DeviceDefault_Light_Dialog));
关于java - 如何在 Android 的 AlertDialog 中设置主题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9448147/