【发布时间】:2017-01-14 21:21:41
【问题描述】:
这是在我的应用程序中显示的 AlertDialog 的图片。 它应该有一个拒绝和一个接受按钮。
如你所见,它没有:
我无法重现此错误,因为我没有搭载 Android 7.1 的手机。图片是在 Google Pixel 上拍摄的,然后发送给我。
测试此应用程序的所有其他 Android 版本均未遇到此错误。 (版本 4.1、6.0.1)
下面是创建对话框的方法代码:
/**
* Creates a 2 options dialog.
* @param context
* @param title headline of the dialog
* @param message main text of the dialog
* @param accept listener for the accept button
* @param deny listener for deny button
* @param acceptText text of the positive answer button
* @param denyText text of the negative answer button
* @param cancelable weather a click to anywhere but the presented buttons dismisses the dialog
* @return a created dialog instance. To display it call show()
*/
public static AlertDialog createAcceptDenyDialog(Context context,
String title, String message, String acceptText,
String denyText, boolean cancelable,
DialogInterface.OnClickListener accept,
DialogInterface.OnClickListener deny,
DialogInterface.OnDismissListener dismiss){
AlertDialog.Builder alertDialog = new AlertDialog.Builder(context)
.setTitle(title)
.setMessage(message)
.setPositiveButton(acceptText, accept)
.setNegativeButton(denyText, deny)
.setCancelable(cancelable)
.setOnDismissListener(dismiss);
return alertDialog.create();
}
这是导致显示对话框的代码:
public void showRequestErrorRetryDialog(String title, String message) {
Dialog dialog = DialogFactory.createAcceptDenyDialog(this
, title
, message
, getString(R.string.retry_button)
, getString(R.string.abort_button)
, true
, (dialogInterface, i) -> {
onStartServerCommunication();
showProgressOverlay();
}
, null
, null);
dialog.show();
}
如你所见,我使用的是 retrolambda。
有人知道会发生什么吗?
【问题讨论】:
-
也许您传递了错误的上下文?您的方法中的
this是什么?在Android 7中对我有用的是new AlertDialog.Builder(context).attributes.show()..(属性都是.setTitle().setPositiveButton()等方法。 -
方法 showRequestErrorRetryDialog 从应该显示对话框的活动中调用。因此,“this”是活动的上下文
-
这是活动呢?为什么不使用 getApplicationContext() ?
-
你需要明确设置主题,看这里:stackoverflow.com/questions/39621606/…
标签: android android-7.1-nougat