如何在alertdialog按钮中添加按钮点击效果android
问题描述:
我有一个alertdialog框,其中我已经为alertdialog按钮定制了背景。在这个我想添加一个按钮效果点击任何人都可以告诉我我如何为alertdialog添加按钮点击效果以及如何更改警报对话框中按钮的大小。如何在alertdialog按钮中添加按钮点击效果android
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
NewDaybook_Activity.this);
// set title
alertDialogBuilder.setTitle(R.string.app_name);
// set dialog message
alertDialogBuilder
.setMessage(R.string.clickyestoexit)
.setCancelable(false)
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// if this button is clicked, close
// current activity
Intent a = new Intent(Intent.ACTION_MAIN);
a.addCategory(Intent.CATEGORY_HOME);
a.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(a);
}
})
.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// if this button is clicked, just close
// the dialog box and do nothing
dialog.cancel();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
Button nbutton = alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE);
nbutton.setTextColor(getResources().getColor(R.color.colorAccent));
Button pbutton = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
pbutton.setBackgroundColor(getResources().getColor(R.color.colorAccent));
pbutton.setPadding(0, 10, 10, 0);
pbutton.setTextColor(Color.WHITE);
Onclick已经添加了两个按钮你想要做什么请解释 –
@santoshkumar当我们点击按钮我想显示按钮的涟漪效应 –