AlertDialog 在某些设备上破坏了布局
AlertDialog broken layout on some devices
我在使用以下创建 AlertDialog 的方法时遇到问题:
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this)
.setTitle(R.string.deletion_title)
.setMessage(R.string.options_deleteExternalConfirm)
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Utils.deleteExternalDir();
dialog.cancel();
}
})
.setNegativeButton(R.string.no, null);
alertDialog.show();
虽然该对话框在大多数设备上看起来都不错,但在其他设备(即带有 Android 5.0.1 的 Galaxy S4 - GT-I9505)上存在布局问题,请参见附图:。
这是什么原因,我该如何解决?
(除了在 Build.PRODUCT.equals("GT-I9505")
时向自定义对话框添加填充外,因为可能有手机有同样的问题但我不知道)
事实证明这是 android:fitsSystemWindows 和 Android Lollipop 的问题,例如 this answer。
我在使用以下创建 AlertDialog 的方法时遇到问题:
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this)
.setTitle(R.string.deletion_title)
.setMessage(R.string.options_deleteExternalConfirm)
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Utils.deleteExternalDir();
dialog.cancel();
}
})
.setNegativeButton(R.string.no, null);
alertDialog.show();
虽然该对话框在大多数设备上看起来都不错,但在其他设备(即带有 Android 5.0.1 的 Galaxy S4 - GT-I9505)上存在布局问题,请参见附图:
(除了在 Build.PRODUCT.equals("GT-I9505")
时向自定义对话框添加填充外,因为可能有手机有同样的问题但我不知道)
事实证明这是 android:fitsSystemWindows 和 Android Lollipop 的问题,例如 this answer。