基于对话框的 AlertDialog 显示不当

AlertDialog based on dialog shows inappropriately

我有一个显示为对话框的 activity,在 Manifest.xml 中,我将 activity 设置为:"android:theme="@android: style/Theme.Dialog",并且运行良好;此外,我想要一个 AlertDialog 从这个 activity 显示,但是由于 Activity 的 Theme 是 Dialog,所以 AlertDialog 的显示样式与基于Activity的AlertDialog不同。AlertDialog的属性应该如何设置才能看起来像普通的?

你可以试试这个:

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);

希望对您有所帮助。