首页 > 解决方案 > 如何在android studio中圆角对话框

问题描述

刚开始学习android开发,想做一个好看的对话框。

这就是我现在所拥有的。

这就是我想要的样子。

我尝试查找它,其中大多数都告诉我制作一个新形状并将其添加为对话框背景,但我似乎不明白如何将新形状设置为背景。

这是我的对话框代码:

new AlertDialog.Builder(this)
                .setTitle(" ")
                .setMessage("Congrats! Player " + winner +" wins!")
                .setPositiveButton("Play again", new DialogInterface.OnClickListener()
                {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        //my code here
                    }

                })
                .setNegativeButton("F", null)
                .show();

如何将我的形状背景 xml 链接到此对话框以及如何使正按钮具有屏幕截图中的背景?

编辑:问题已编辑,因为我已经尝试过下面的方法我似乎不理解它,除了它有多个部分(页眉,页脚),我真的不需要我的要求更基本。

标签: javaandroidandroid-studioandroid-alertdialogrounded-corners

解决方案


您可以轻松地为您的对话设置自定义AlertDialog视图setView(View view)

您的代码将是这样的:

View view = inflater.inflate(R.layout.your_layout_name, null);
new AlertDialog.Builder(this)
                .setView(view)
                .create()
                .show();


推荐阅读