简体   繁体   English

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

[英]How do I add an icon to the alert box?

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: 您可以通过指定资源的drawable或id来使用builder.setIcon()方法:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM