无法在android默认对话框中看到完整的标题文本,因为它在文本开头显示了ellipsize

时间:2017-09-06 08:27:49

标签: android alertdialog android-alertdialog

我使用默认的Android Alert Dialog来显示2行描述和消息。当我在代码下面运行它在android中的标题文本开头显示ellipsize。

public void showDeleteConfirmationDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(getString(R.string.dialog_document_title));
    builder.setMessage(getString(R.string.dialog_document_message));
    builder.setPositiveButton(R.string.dialog_btn_yes, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    File file;
                    for (String scanImagePath : scanImageList) {
                        file = new File(scanImagePath);
                        if (file.exists()) {
                            file.delete();
                        }
                    }
                    finish();
                }
            }).run();
        }
    });
    builder.setNegativeButton(R.string.dialog_btn_cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.dismiss();
        }
    });
    AlertDialog dialog = builder.create();
    dialog.show();
}

并在标题上开始ellipsize。 enter image description here

2 个答案:

答案 0 :(得分:0)

试试这个

AlertDialog.Builder builder = new AlertDialog.Builder(this);

TextView textView = (TextView) dialog.findViewById(android.R.id.title);
textView.setMaxLines(2);
textView.setText(getString(R.string.dialog_document_title));

builder.setMessage(getString(R.string.dialog_document_message));
 builder.setPositiveButton(R.string.dialog_btn_yes, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    File file;
                    for (String scanImagePath : scanImageList) {
                        file = new File(scanImagePath);
                        if (file.exists()) {
                            file.delete();
                        }
                    }
                    finish();
                }
            }).run();
        }
    });
    builder.setNegativeButton(R.string.dialog_btn_cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.dismiss();
        }
    });
    AlertDialog dialog = builder.create();
    dialog.show();
}

答案 1 :(得分:0)

使用android.app.AlertDialog或android.support.v7.app.AlertDialog都无法复制你的现象。可能我无法帮助你。但是你可能需要将方法run()更改为start(),通常我们让对话框的enter image description here消息显示长词而不是标题,标题只是setText(“提示”)。(我的英语很差,请...)