在AlertDialog中显示长消息 [英] Show Long Message in AlertDialog

查看:96
本文介绍了在AlertDialog中显示长消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下代码在Default AlertDialog中显示一条冗长的消息.

I am trying to display an lengthy message in Default AlertDialog with following code.

public static void showAlert(String message, Context con) {
    AlertDialog.Builder dialog = new AlertDialog.Builder(con);
    dialog.setTitle(message);
    dialog.setPositiveButton(" OK ", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.dismiss();

        }
    });
    dialog.show();

}

但是当我传递长消息时,警告对话框"不会显示完整的消息.我可以按中心对齐Dialog的文本吗?我不想使用自定义对话框".

But when I pass long message Alert Dialog does not display full message. Can I align text of Dialog by center. I dont want to use Custom Dialog.

推荐答案

更改

dialog.setTitle(message);

dialog.setMessage(message);

,如果要居中对齐文本,则必须创建 如下例所示的textview:

and if you want to center align the text, you'll have to create a textview like in the following example:

    AlertDialog.Builder dialog = new AlertDialog.Builder(con);
    dialog.setTitle(message);
    dialog.setPositiveButton(" OK ", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.dismiss();

        }
    });
    dialog.show();

// Must call show() prior to fetching text view
TextView messageView = (TextView)dialog.findViewById(android.R.id.message);
messageView.setGravity(Gravity.CENTER);

摘自: Android对话框中的中心消息

这篇关于在AlertDialog中显示长消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆