2017-06-01 7 views
3

Ich versuche, meinem AlertDialog Builder einen Titel hinzuzufügen. Wenn ich das Thema hinzufüge, wird mein Titel in den Auswahlbereich verschoben.
Hier ist das erste Beispiel:Das Anwenden eines Designs auf AlertDialog Builder führt dazu, dass der Titel nicht korrekt funktioniert

classificationButton.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      AlertDialog.Builder builder = new AlertDialog.Builder(
        new ContextThemeWrapper(mContext, android.R.style.Theme_Holo_Dialog)); 
        //building my selection options 
        builder.setItems(classificationList, new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int which) { 
          String desiredClassification = classificationList[which]; 
          if (!getClassification().equals(desiredClassification)) { 
           CallsignContract.updateClassification(desiredClassification, mContext); 
           setClassification(desiredClassification); 
           classificationButton.setText(desiredClassification); 
          } 
         } 
        }); 
        builder.setTitle(R.string.classification_alert_header) 
          .create().show(); 
     } 
    }); 

Dies ist das Ergebnis.
Bei diesem zweiten Versuch erstelle ich einen Alertdialog vom Builder und gebe diesem einen Titel. Das Ergebnis ist der korrekte Titel, aber der Titel erscheint wieder im Auswahlbereich.

 classificationButton.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      AlertDialog.Builder builder = new AlertDialog.Builder(
        new ContextThemeWrapper(mContext, android.R.style.Theme_Holo_Dialog)); 
         //building my selection options 
         builder.setItems(classificationList, new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int which) { 
          String desiredClassification = classificationList[which]; 
          if (!getClassification().equals(desiredClassification)) { 
           CallsignContract.updateClassification(desiredClassification, mContext); 
           setClassification(desiredClassification); 
           classificationButton.setText(desiredClassification); 
          } 
         } 
        }); 
      AlertDialog alertDialog = builder.create(); 
      alertDialog.setTitle(R.string.classification_alert_header); 
      alertDialog.show(); 
     } 
    }); 


double titles

Vielen Dank!

+0

Ist Ihr Titel nicht in 'classificationList' Array? –

+0

@UilqueMessias Nein. Das Array classificationList enthält nur Nicht spezifiziert, Nicht klassifiziert, Vertraulich und Geheimnis. – RYDiiN

Antwort

1

Um nur einen Titel anzuzeigen, müssen Sie alertDialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE) aufrufen.

AlertDialog.Builder builder = new AlertDialog.Builder(
    new ContextThemeWrapper(mContext, android.R.style.Theme_Holo_Dialog) 
); 

//building my selection options 
builder.setItems(classificationList, 
    new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int which) { 
      String desiredClassification = classificationList[which]; 

      if (!getClassification().equals(desiredClassification)) { 
       CallsignContract.updateClassification(desiredClassification, mContext); 
       setClassification(desiredClassification); 
       classificationButton.setText(desiredClassification); 
      } 
     } 
    } 
); 

AlertDialog alertDialog = builder.create(); 
alertDialog.setTitle(R.string.classification_alert_header); 
// Requesting dialog to remove the title 
alertDialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE); 
alertDialog.show(); 
Verwandte Themen