2017-01-14 1 views
5

Это изображение AlertDialog, которое показано в моем приложении. У этого должно быть есть кнопка deny и accept.Отсутствующие кнопки диалога под Android 7.1.1

Как вы можете видеть это не имеет:

enter image description here

Я не могу воспроизвести эту ошибку, поскольку я не имею телефон с 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(); 
} 

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

Есть ли у кого-нибудь идеи, что происходит?

+0

Возможно, вы не в неправильном контексте? Что такое «это» в вашем методе? То, что отлично работает для меня в Android 7, - это новый AlertDialog.Builder (контекст) .attributes.show() '.. (Атрибуты - это все такие методы, как' .setTitle() '' .setPositiveButton() 'и т. Д. – creativecreatorormaybenot

+0

Метод showRequestErrorRetryDialog вызывается из действия, в котором должен отображаться диалог. «this» является поэтому контекстом активности – zetain

+0

Это действие тогда? Почему вы не используете getApplicationContext()? – creativecreatorormaybenot

ответ

12

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

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

Смежные вопросы