I want to add an icon to the alert dialog box. How do I add an icon to the alert box ? Please help me.
public void onClick(View arg0) {
if(TextUtils.isEmpty(entermass.getText().toString()) || TextUtils.isEmpty(enterheight.getText().toString()))
{
if(TextUtils.isEmpty(entermass.getText().toString()) || TextUtils.isEmpty(enterheight.getText().toString()))
{
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Developer's Check");
builder.setMessage("Either Of The Text Fields Are Empty");
builder.setPositiveButton("OKAY", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
You can use builder.setIcon()
method by specifying drawable or id of the resource:
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this)
.setIcon(R.drawable.ic_launcher) //using id of the drawable resource
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.