这是我的应用程序中显示的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.
有谁知道会发生什么?
解决方法
对我有用的解决方案是在我的style.xml上添加以下行:
// your main style <style name="YourStyleName" parent="Theme.AppCompat.Light.NoActionBar"> <item name="android:alertDialogTheme">@style/AlertDialogTheme</item> <item name="alertDialogTheme">@style/AlertDialogTheme</item> </style> // dialog style <style name="AlertDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert"> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> <item name="buttonBarButtonStyle">@style/DialogButtonStyle</item> </style> // button's dialog style <style name="DialogButtonStyle" parent="@style/Widget.AppCompat.Button.ButtonBar.AlertDialog"> <item name="android:textColor">@color/colorPrimary</item> </style>
它工作得很好,我希望它会帮助你们.