如何在警报框中添加图标?

时间:2014-03-05 19:36:27

标签: java android dialog icons alert

我想在警告对话框中添加一个图标。如何在警报框中添加图标? 请帮帮我。

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();
                }

1 个答案:

答案 0 :(得分:4)

您可以通过指定资源的drawable或id来使用builder.setIcon()方法:

AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this)
            .setIcon(R.drawable.ic_launcher) //using id of the drawable resource