Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change background color of android default alert dialog

I have a default alert dialog with listview of Text & Radio buttons.

I need to replace the image instead of text (Replace images instead of Facebook credit,paypal,Credit card shown below) & also needs to change alert dialog's background color.

I put style.xml file inside values folder also.

How could I implement that file in below code for changing background color?

My code:

 final CharSequence[] items = {"Facebook credit", "Paypal", "Credit Card"};

            //ContextThemeWrapper ctw = new ContextThemeWrapper( this, R.style.AboutDialog );
            AlertDialog.Builder builder = new AlertDialog.Builder(paymentPage.this);
            builder.setTitle("Payment Gateway");
            builder.setIcon(R.drawable.gate);
            builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int item) {
                   // Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
                }
            });

            builder.setPositiveButton("Yes",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            payPalPayment();
                        }


                    });
            builder.setNegativeButton("No",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            Toast.makeText(paymentPage.this, "Fail", Toast.LENGTH_SHORT).show();
                        }
                    });
            AlertDialog alert = builder.create();
            alert.show();
        }
    });

My image:

enter image description here

like image 533
sanjay Avatar asked Nov 13 '22 00:11

sanjay


1 Answers

You should Customize AlertDialog Theme. Look at following post.

https://sites.google.com/site/androidhowto/how-to-1/customize-alertdialog-theme

This library might help you : https://github.com/avast/android-styled-dialogs

like image 165
Nauman Afzaal Avatar answered Dec 19 '22 17:12

Nauman Afzaal