Reputation: 2620
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:
Upvotes: 5
Views: 10906
Reputation: 1046
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
Upvotes: 1
Reputation: 2403
I kinda faced the same problem. And the only way to solve it was extending my own version of layout. I see that in your case it is an AlertDialog. What I recommend you to do, is to create a unique class, that is your customized AlertDialog and create a layout for this, and then you inflate this.
Here is a post that helped me a lot.
I followed this post and solved my problem with customizing dialogs.
Please, if you have more doubts, let me know.
Thanks.
Upvotes: 0