2015-12-12 26 views
5

Gibt es eine Möglichkeit, die Titelhintergrundfarbe von AlertDialog (android.support.v7.app.AlertDialog) zu ändern? Zeit in meinem Thema habe ichAndroid AlertDialog Titel Hintergrundfarbe

<item name="alertDialogTheme">@style/AppCompatAlertDialogStyle</item> 

<style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert"> 
     <item name="colorAccent">@color/colorAccent</item> 
    </style> 

und ich bin immer es so,

enter image description here

Wie kann ich es so aussehen zu lassen,

enter image description here

Verwendung

<style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert"> 
     <item name="colorAccent">@color/colorAccent</item> 
     <item name="android:windowTitleStyle">@style/DialogTitle</item> 
    </style> 

    <style name="DialogTitle"> 
     <item name="android:background">@color/colorPrimary</item> 
    </style> 

gibt

enter image description here

Alle Ideen, wie dies erreicht werden kann?

+0

haben Sie eine Lösung finden für diese erstellen? – Hunt

+0

Ich denke, die Antwort von Mr.Songoku ist eine beste Antwort http://Stackoverflow.com/a/42135263/7797592 – m7mdbook

Antwort

0

Use custom Alerbox, verwenden Sie diesen Code auf click.I einen benutzerdefinierten Layout "alert_input" gemacht und OK und Abbrechen wird Option

LayoutInflater layoutInflater = LayoutInflater.from(Login.this); 
       View promptView = layoutInflater.inflate(R.layout.alert_input, null); 
       final EditText editText = (EditText) promptView.findViewById(R.id.alertEdit2); 
       final EditText editText2 = (EditText) promptView.findViewById(R.id.alertEdit3); 
       final TextView at=(TextView)findViewById(R.id.alertText); 

       AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(Login.this,AlertDialog.THEME_HOLO_LIGHT); 
       alertDialogBuilder.setView(promptView); 
       alertDialogBuilder.setCancelable(false) 
         .setPositiveButton("OK", new DialogInterface.OnClickListener() { 
          public void onClick(DialogInterface dialog, int id) { 


          } 
         }) 
         .setNegativeButton("Cancel", 
           new DialogInterface.OnClickListener() { 
            public void onClick(DialogInterface dialog, int id) { 
             dialog.cancel(); 
            } 
           }); 

       // create an alert dialog 
       AlertDialog alert = alertDialogBuilder.create(); 
       alert.show(); 
6

Sie können wie diese benutzerdefinierten Titel

LayoutInflater inflater = this.getLayoutInflater(); 

    View titleView = inflater.inflate(R.layout.custom_title, null); 

    new AlertDialog.Builder(SubCategoryActivity.this) 
         .setCustomTitle(titleView); 
gerade eingestellt angezeigt

und in custom_title Layout können Sie benutzerdefinierte Titel wie dieser

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:paddingLeft="10dp" 
     android:paddingRight="10dp" 
     android:id="@+id/llsubhead" 
     android:background="@color/colorPrimary"> 

     <TextView 
      android:id="@+id/exemptionSubHeading4" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="10dp" 
      android:layout_marginBottom="10dp" 
      android:layout_weight="1" 
      android:text="Exemption Sub Head" 
      android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium" 
      android:textColor="@color/white" /> 
    </LinearLayout> 
</LinearLayout> 
+0

Danke für Ihre Antwort:) - nett – Kalanidhi

Verwandte Themen