2017-01-14 12 views
5

To jest obraz AlertDialog, który jest wyświetlany w mojej aplikacji. To powinno być mieć przycisk odmowy i przycisk akceptowania.Brakujące przyciski dialogowe pod Androidem 7.1.1

Jak widać to nie ma:

enter image description here

nie mogę odtworzyć tego błędu jak ja nie masz telefon z Androidem 7.1. Zdjęcie zostało zrobione w Google Pixel i wysłać do mnie.

Wszystkie inne wersje Androida, na których ta aplikacja została przetestowana, nie napotkały tego błędu. (wersje 4.1, 6.0.1)

Oto kod metody tworzenia okna:

/** 
* 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(); 
} 

ten kod powodując okna mają być wyświetlane:

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(); 
} 

jak ty widzę, używam retrolambdy.

Czy ktoś ma pomysł co się dzieje?

+0

Może podajesz zły kontekst? Co to jest "ta" w twojej metodzie? To, co działa dobrze w Androidzie 7, to 'new AlertDialog.Builder (context) .attributes.show()' .. (Atrybuty to wszystkie metody takie jak '.setTitle()' '.setPositiveButton()' etc .. – creativecreatorormaybenot

+0

Metoda showRequestErrorRetryDialog jest wywoływany z poziomu działania, w którym powinno być wyświetlane okno dialogowe .Tak więc jest to kontekst działania – zetain

+0

, to jest wtedy aktywność? Dlaczego nie używasz getApplicationContext()? – creativecreatorormaybenot

Odpowiedz

12

Rozwiązanie który pracuje dla mnie było, aby dodać następujące linie na mojej 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> 

To działa doskonale, mam nadzieję, że to pomoże wam.

Powiązane problemy