How to remove border in custom AlertDialog?

浪尽此生 提交于 2019-12-18 09:17:53

问题


I'm trying to create custom AlertDialog with an image text and buttons. When I display it I get a white border which looks horrible.

How can I get rid of that white border?

Here my custom Dialog:

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();

    }

As you can see the topborder and image have a space in 2-3 px.


回答1:


try this use Dialog Instead of AlertDialog.Builder

.. for remove border line from Dialog..

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



回答2:


This will remove borders:

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!");

Also, I had a problem using a custom Dialog in full screen mode. my phone's notification bar kept showing up as long as the dialog wasn't dismissed. with a customized AlertDialog, this won't be an issue ;)




回答3:


If you want the Dialog Border to appear in any colour you wish you have to use layout style and a theme. There is an excellent article about it here: http://blog.androgames.net/10/custom-android-dialog/



来源:https://stackoverflow.com/questions/5910239/how-to-remove-border-in-custom-alertdialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!