2015-12-12 28 views
5

Czy istnieje sposób na zmianę koloru tła tytułu AlertDialog (android.support.v7.app.AlertDialog)? Obecnie w moim tematem mamAndroid AlertDialog tytuł koloru tła

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

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

i jestem coraz to tak,

enter image description here

Jak mogę zrobić to wyglądać tak,

enter image description here

Używanie

<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> 

daje

enter image description here

jakieś pomysły w jaki sposób można to osiągnąć?

+0

znaleźliście jakieś rozwiązanie dla tego? – Hunt

+0

Myślę, że odpowiedź Mr.Songoku to najlepsza odpowiedź http://stackoverflow.com/a/42135263/7797592 – m7mdbook

Odpowiedz

0

Wykorzystanie niestandardowych Alerbox, użyj tego kodu na click.I wykonane niestandardowego Layout „alert_input” i OK i Anuluj opcja będzie udostępniana

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

można po prostu ustawić niestandardowy tytuł jak ten

LayoutInflater inflater = this.getLayoutInflater(); 

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

    new AlertDialog.Builder(SubCategoryActivity.this) 
         .setCustomTitle(titleView); 

iw układzie custom_title można utworzyć niestandardowy tytuł jak ten

<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

Dzięki za odpowiedź:) - nice – Kalanidhi