Отсутствующие диалоговые кнопки в 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 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();
}

Как видите, я использую ретролямбду.

Кто-нибудь знает, что происходит?


person zetain    schedule 14.01.2017    source источник
comment
Может быть, вы передаете неправильный контекст? Что такое this в вашем методе? Что отлично работает для меня в Android 7, так это new AlertDialog.Builder(context).attributes.show().. (Атрибуты - это все методы, такие как .setTitle() .setPositiveButton() и т. д..   -  person creativecreatorormaybenot    schedule 15.01.2017
comment
Метод showRequestErrorRetryDialog вызывается из действия, в котором должно отображаться диалоговое окно. поэтому это контекст деятельности   -  person zetain    schedule 15.01.2017
comment
это активность тогда? Почему вы не используете getApplicationContext()?   -  person creativecreatorormaybenot    schedule 15.01.2017
comment
Является ли это предпочтительным для использования контекста активности при создании диалогов? Потому что у них нет конкретной причины. Не могли бы вы уточнить?   -  person zetain    schedule 15.01.2017
comment
Мне просто интересно, почему вы используете его вместо getApplicationContext . Как я уже сказал, я действительно не вижу причины вашей проблемы, поэтому вам, возможно, придется проявить творческий подход. Моя версия работает для меня на Nougat, так что да   -  person creativecreatorormaybenot    schedule 15.01.2017
comment
Вам необходимо явно установить тему, см. здесь: stackoverflow.com/questions/39621606/   -  person netcyrax    schedule 16.01.2017
comment
Возможный дубликат отсутствующих кнопок в AlertDialog | Android 7.0 (Nexus 5x)   -  person Shirish Herwade    schedule 21.11.2017


Ответы (1)


Решение, которое работает для меня, состояло в том, чтобы добавить следующие строки в мой 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>

Он работает отлично, я надеюсь, что это поможет вам, ребята.

person tryp    schedule 22.03.2017
comment
Это работает, если вы используете Android.Support.V7.App.AlertDialog. Для меня было достаточно определения следующего стиля<style name="AlertDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert"> <item name="android:textColor">@color/primaryColor</item> </style> - person AZ_; 18.02.2020