如何在自定义AlertDialog中去掉边框?

3
我正在尝试创建带有图像文本和按钮的自定义AlertDialog。当我显示它时,会出现一个看起来很糟糕的白色边框。
如何去掉那个白色边框?
以下是我的自定义对话框:
public LinearLayout customeLL;
    public void  alertD()
    {
        AlertDialog ad;
        AlertDialog.Builder  builder;
        Context mContext = getApplicationContext();
        TextView a = new TextView(getApplicationContext());
        a.setText("Test dialog");
        ImageView img = new ImageView(getApplicationContext());
        img.setBackgroundResource(R.drawable.bottombar_bg);
        LinearLayout customeLL = new LinearLayout(getApplicationContext());
        customeLL.setOrientation(LinearLayout.VERTICAL);
        customeLL.addView(img,curWidth,37);
        customeLL.addView(a,curWidth,37);
        builder = new AlertDialog.Builder(myClass.this);
        builder.setView(customeLL);
        ad=builder.create();
        ad.show();

    }

正如您所看到的,顶部边框和图像之间有2-3像素的间隙。


白边是什么意思? - ingsaurabh
只需要一个边框。在 alertDialog 中添加边框(默认为白色边框)。 - Peter
你可以使用 Dialog 代替 Alert 吗? - Niranj Patel
当然,如果我可以删除文件夹的话:(。但是所有人都告诉我我必须在alertdialog中创建自定义(用图像代替标题)。我只想垂直排列:图像(代替标题),文本1,文本2,文本3,btn1,btn2.... - Peter
你可以在对话框中添加任何你想要的布局。 - Niranj Patel
是的,但是边框怎么办?还有标题吗?如何在对话框中设置图像而不是标题? - Peter
3个回答

9

尝试使用Dialog替代AlertDialog.Builder

...以去除对话框的边框线...

Dialog dialog = new Dialog(this,android.R.style.Theme_Translucent_NoTitleBar);

谢谢,但我只需要移除标题。我需要移除边框:(请看图片顶部的白线-是否可以移除? - Peter
我刚刚发布了一个Gist,展示了一个带有自定义主题、无标题或边框的浮动对话框:https://gist.github.com/2643546 - Chris Blunt

2
这将去除边框:
AlertDialog ad;
ad= new AlertDialog.Builder(context).create();
ad.show();
ad.setContentView(R.layout.dialog_layout); // set your custom layout

// Then initialize your dialog views like this
TextView txt= (TextView) ad.findViewById(R.id.dialog_text); // a TextView inside dialog 
                                                            // layout
txt.setText("I'm a custom dialog!");

此外,我在全屏模式下使用自定义对话框时遇到了问题。只要对话框没有解除,我的手机通知栏就会一直显示出来。但如果使用自定义的AlertDialog,则不会出现这个问题 ;)


0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接