Question

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();
                }
Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top