2016-06-20 24 views
0

Ich versuche, die Akzentfarbe für AlertDialog-Schaltflächen anzupassen. Aber es nimmt keinen Einfluss, es scheint, dass es die Farbe vom System erbt. Hier ist mein Stil/Thema.Benutzerdefiniertes Design für AlertDialog funktioniert nicht

<color name="actionable_items">#0574ac</color> <!-- it is blue color --> 
    <style name="LLDialog" parent="Theme.AppCompat.Light.Dialog.Alert"> 
     <!--buttons color--> 
     <item name="colorAccent">@color/actionable_items</item> 
     <!--item RadioButton or CheckBox color--> 
     <item name="colorControlActivated">@color/actionable_items</item> 
     <item name="colorPrimary">@color/actionable_items</item> 
     <item name="colorPrimaryDark">@color/actionable_items</item> 
     <item name="android:listChoiceIndicatorMultiple">@color/actionable_items</item> 
     <item name="android:listChoiceIndicatorSingle">@color/actionable_items</item> 
    </style> 

Hier ist mein Code, der versucht, den Alertdialog zu erstellen.

Der letzte AlertDialog hat keine Schaltflächen mit der gleichen Textfarbe. Die Textfarbe ist ähnlich wie grün. Es scheint, als würde die Farbe vom System anstelle des benutzerdefinierten Themas übernommen. Hier ist das Bild: enter image description here

EDIT1:

ich den Gebrauch versucht die AlertDialog.Builder aber es gibt mir das gleiche Ergebnis.

final AlertDialog.Builder removePlaceDialog = AlertDialog.Builder(new ContextThemeWrapper(context, 
                  R.style.LLDialog)); 
       removePlaceDialog.setTitle(getString(R.string.delete_place, placeName)); 
       removePlaceDialog.setMessage(getString(R.string.delete_place_message)); 
       removePlaceDialog.setPositiveButton(R.string.ok_button, new DialogInterface.OnClickListener() { 

        public void onClick(DialogInterface dialog, int which) { 
         .... 
         .... 
        } 
       }); 
       removePlaceDialog.setNegativeButton(R.string.cancel, null); 
       removePlaceDialog.create().show(); 

Edit2:

Ich habe auch versucht die Akzentfarbe für das Dialogfeld zu ändern, aber ich sehe nicht, dass Farbe:

<style name="LLDialog" parent="Theme.AppCompat.Light.Dialog.Alert"> 
     <!--buttons color--> 
     <item name="colorAccent">#990000</item> 
     ... 
     ... 
</style> 

Auch dies nicht ändert Knopftextfarbe :(.

+0

Warum Sie 'CustomPopupBuilder' verwenden, können Sie stattdessen den Standard' AlertDialog' verwenden. –

+0

@jankigadhiya Ich habe den AlertDialog aber das gleiche Ergebnis verwendet. es passt den alertDialog nicht an mein Thema/Stil an. – Rakesh

Antwort

0

Hier ein Beispiel hoffen, dass es Ihnen

hilft

XML Layout

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="#00000000" 
> 

<RelativeLayout 
    android:id="@+id/rlmain" 
    android:layout_width="fill_parent" 
    android:layout_height="150dip" 
    android:layout_alignParentLeft="true" 
    android:layout_centerVertical="true" 
    android:background="#569CE3" > 

    <RelativeLayout 
     android:id="@+id/relativeLayout1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginLeft="25dip" 
     android:layout_marginTop="10dip" > 

     <TextView 
      android:id="@+id/title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentTop="true" 
      android:text="Are you Sure?" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:textColor="#ffffff" 
      android:textSize="13dip" /> 
    </RelativeLayout> 

    <RelativeLayout 
     android:id="@+id/relativeLayout2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/relativeLayout1" 
     android:layout_alignRight="@+id/relativeLayout1" 
     android:layout_below="@+id/relativeLayout1" 
     android:layout_marginTop="5dip" > 
    </RelativeLayout> 

    <ProgressBar 
     android:id="@+id/process" 
     style="?android:attr/progressBarStyleSmall" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginRight="3dip" 
     android:layout_marginTop="3dip" /> 

    <RelativeLayout 
     android:id="@+id/relativeLayout3" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/relativeLayout2" 
     android:layout_below="@+id/relativeLayout2" 
     android:layout_toLeftOf="@+id/process" > 

     <TextView 
      android:id="@+id/message" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_centerVertical="true" 
      android:text="Medium Text" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:textColor="#ffffff" 
      android:textSize="13dip"/> 

    </RelativeLayout> 

    <Button 
     android:id="@+id/next_button" 
     android:layout_width="90dip" 
     android:layout_height="35dip" 
     android:layout_alignParentBottom="true" 
     android:textColor="@drawable/button_text_color" 
     android:background="@drawable/blue_button" 
     android:layout_marginBottom="5dp" 
      android:textSize="10dp" 

     android:layout_alignRight="@+id/relativeLayout3" 
     android:text="Okay" /> 

    <Button 
     android:id="@+id/button2" 
     android:text="Cancel" 
     android:textColor="@drawable/button_text_color" 
     android:layout_width="90dip" 
     android:layout_height="35dip" 
     android:layout_marginBottom="5dp" 
     android:background="@drawable/blue_button" 
     android:layout_marginRight="7dp" 
     android:textSize="10dp" 
     android:layout_alignParentBottom="true" 
     android:layout_toLeftOf="@+id/next_button" 
     /> 

</RelativeLayout> 
0

Wenn Ihr Thema Ihre Alertdialog Tasten Farbe nicht reflektieren, können Sie es verwalten programmatisch auch, die nützlich sein könnten.

AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.AppCompatAlertDialogStyle)); 
    builder.setCancelable(false); 

    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH); 
    String message ="message"; 
    builder.setTitle("title"); 

    builder.setMessage(message); 
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { 
     @Override 
     public void onClick(DialogInterface dialog, int which) { 

     } 
    }); 
    // builder.setNegativeButton("No, Thanks", null); 
    //builder.show(); 
    AlertDialog alert = builder.create(); 
    alert.show(); 
    Button pbutton = alert.getButton(DialogInterface.BUTTON_POSITIVE); 
    pbutton.setTextColor(getResources().getColor(R.color.colorAccent)); 
    Button nbutton = alert.getButton(DialogInterface.BUTTON_NEGATIVE); 
    nbutton.setTextColor(getResources().getColor(R.color.accent)); 

Hier können Sie Farbe beiden Tasten ändern, wenn Sie erforderlich, hoffen, es könnte userful für Sie

0

ich hatte das gleiche Problem, und das ist, wie ich es gelöst:

In styles.xml erklären, Ihr Thema und setzen Sie das Attribut android:alertDialogTheme:

<style name="YourTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
    <!-- your theme attributes here --> 
    <item name="android:alertDialogTheme">@style/YourDialogTheme</item> 
</style> 

<style name="YourDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert" > 
    <!-- your dialog-theme attributes here --> 
</style> 

Nun, wenn Sie eine Alertdialog zeigen, wie so ...

AlertDialog.Builder builder = new AlertDialog.Builder(activity); //where activity is an Activity with the theme attribute set to android:theme="@style/YourTheme" (in AndroidManifest) 
//... 
builder.show(); 

... der Dialog sollte die accentColor und alles auf, was Sie in @ Stil angegeben/YourDialogTheme

2

das Erstellen unter einen neuen Stil wie:

<style name="AlertDialogCustom" parent="@android:style/Theme.Holo.Light.Dialog">   
    <!--buttons color--> 
    <item name="colorAccent">@color/actionable_items</item> 
    <!--item RadioButton or CheckBox color--> 
    <item name="colorControlActivated">@color/actionable_items</item> 
    <item name="colorPrimary">@color/actionable_items</item> 
    <item name="colorPrimaryDark">@color/actionable_items</item> 
    <item name="android:listChoiceIndicatorMultiple">@color/actionable_items</item> 
    <item name="android:listChoiceIndicatorSingle">@color/actionable_items</item> 
</style> 

Und dann in der Klasse :

AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(new ContextThemeWrapper(context, R.style.AlertDialogCustom));  
AlertDialog alertDialog = dialogBuilder.create();  
alertDialog.show(); 
3

Überprüfen Sie bitte Ihren AlertDialog-Import. Es sollte von v7 support lib für Styles importiert werden, die auf ältere Android-Versionen angewendet werden sollen.Ich hatte das gleiche Problem und Ändern Import Linie von

import android.app.AlertDialog 

zu

import android.support.v7.app.AlertDialog 

mir geholfen.

Verwandte Themen