【问题标题】:AlertDialog based on dialog shows inappropriately基于对话框的 AlertDialog 显示不当
【发布时间】:2015-08-06 08:32:21
【问题描述】:

我有一个显示为对话框的活动,在 Manifest.xml 中,我将活动设置为:"android:theme="@android:style/Theme.Dialog",它运行良好;此外,我想从这个活动中显示一个AlertDialog,但由于Activity的主题是Dialog,AlertDialog的显示风格与基于Activity的AlertDialog不同。我应该如何设置AlertDialog的属性使其看起来像普通的?

【问题讨论】:

  • 我想要一个通过设置 AlertDialog 的属性的方法,而不是添加布局文件和 setView() 的方法。

标签: android android-alertdialog


【解决方案1】:

你可以试试这个:

Context ctx = this;// your dialog activity;
TypedValue outValue = new TypedValue();
// get theme common dialog theme of application
ctx.getApplicationContext().getTheme().resolveAttribute(android.R.attr.dialogTheme, outValue, true);
int theme = outValue.resourceId;
AlertDialog.Builder bld = new AlertDialog.Builder(ctx, theme);

希望这会有所帮助。

【讨论】:

  • 非常感谢!这正是我所需要的。但是样式并不完全正确,我尝试了 android.R.attr.dialogTheme 和 android.R.attr.AlertDialogTheme,它们都提供了深色背景,我需要一个浅色的。 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多