自定义AlertDialog页脚 [英] Customize AlertDialog Footer

查看:123
本文介绍了自定义AlertDialog页脚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想自定义AlertDialog的页脚,我的意思是,这里的按钮位于的地方。

I want to customize the footer of the AlertDialog, I mean, the place where the buttons are located.

我试图创建一个独立的布局和之前调用它充气 =建设者AlertDialog.Builder();

I tried creating a separate layout and inflating it before calling builder = AlertDialog.Builder();

是这样的:

AlertDialog.Builder builder;
        AlertDialog alertDialog;

        Context mContext = activity;
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(mContext.LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.customdialog, (ViewGroup) activity.findViewById(R.id.layout_root));
        TextView dialogTitle = (TextView) layout.findViewById(R.id.dilaogTitle);
        dialogTitle.setText("Alert Dialog Test");

        TextView closeConfirmationQuestion = (TextView) layout.findViewById(R.id.textview);
        closeConfirmationQuestion.setText("Test for AlertDialog");


        builder = new AlertDialog.Builder(activity).setCancelable(false).setPositiveButton("Yes"), new DialogInterface.OnClickListener()
        {
            public void onClick(DialogInterface dialog, int id)
            {
                //Do something
            }
        }).setNegativeButton("No"), new DialogInterface.OnClickListener()
        {
            public void onClick(DialogInterface dialog, int id)
            {
                dialog.cancel();
            }
        });
        builder.setView(layout);
        alertDialog = builder.create();
        alertDialog.setView(layout, 0, 0, -3, -3);
        alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        alertDialog.show();

不过,我可以自定义只是我AlertDialog的内容,而不是页脚和按钮。这里是如何为:

But I could customize only the content of my AlertDialog, but not the footer and the buttons. Here is how it is:

我需要知道如何自定义按钮和它的持有人,我的意思是,AlertDialog页脚,也许把一种颜色或图片作为背景,而不是标准的灰色的色彩,而且,设置一个自定义的背景的按钮。

I need to know how to customize the buttons and its holder, I mean, the footer of the AlertDialog, maybe put a color or image as its background instead of the standard 'grey' color, and also, set a customized background for the buttons.

感谢。

推荐答案

如果您希望从它的设计格式客场改变AlertDialog,我会建议延长自己的对话框的版本,并使用它。

If you wish to change the AlertDialog away from its designed format, I would recommend extending your own version of the Dialog and using it.

这篇关于自定义AlertDialog页脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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