Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Android 7.1.1下缺少对话框按钮大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我的应用程序中显示的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 accept@R_128_3801@ of the positive answer button
 * @param deny@R_128_3801@ 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,@R_801_8487@an 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>

它工作得很好,我希望它会帮助你们.

大佬总结

以上是大佬教程为你收集整理的Android 7.1.1下缺少对话框按钮全部内容,希望文章能够帮你解决Android 7.1.1下缺少对话框按钮所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。