0

我有一个带有标题和图像的警报生成器:

AlertDialog.Builder builder = new AlertDialog.Builder(activity);                   
builder.setTitle(R.string.pull);
builder.setIcon(R.drawable.tira_cable);
builder.setPositiveButton(R.string.accept, new DialogInterface.OnClickListener() {
   public void onClick(DialogInterface dialog, int id) {
      //actions
   }
   });
AlertDialog dialog = builder.create();
dialog.show();

我检查了问题不在标题中,在图像中,因为如果我评论 setIcon 行,它会显示标题。

4

2 回答 2

1

你必须像这样使用:

AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle(getResources().getString(R.string.pull));
            builder.setIcon(R.drawable.ic_action_search);
            builder.setPositiveButton("OK",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            // actions
                        }
                    });
            AlertDialog dialog = builder.create();
            dialog.show();

你的标题 ll 正在显示...

于 2013-03-20T09:23:39.697 回答
1

使用此代码段修复它!

new AlertDialog.Builder(getApplicationContext())
                            .setIcon(android.R.drawable.ic_dialog_info)
                            .setTitle(getResources().getString(R.string.pull))
                            .setCancelable(false)
                            .setMessage("Quistion???")
                            .setPositiveButton("Yes",
                                    new DialogInterface.OnClickListener() {
                                        public void onClick(
                                                DialogInterface dialog,
                                                int which) {

                                        }

                                    })
                            .setNegativeButton("No",
                                    new DialogInterface.OnClickListener() {
                                        public void onClick(
                                                DialogInterface dialog,
                                                int which) {

                                        }
                                    }).show();
于 2013-03-20T09:18:35.593 回答