Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove black border from AlertDialog builder

I have created a custom dialog using AlertDialog.builder. In this dialog, I am not displaying the title. All works fine but there is a black border in the dialog. So can anyone tell me how can I remove this black border? The code and screenshot are below.

Code in java:

AlertDialog.Builder start_dialog = new AlertDialog.Builder(this);
            
Context mContext = getApplicationContext();
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.custom_dialog2,
                                           (ViewGroup) findViewById(R.id.layout_root));
            
layout.setBackgroundResource(R.drawable.img_layover_welcome_bg);

Button btnPositiveError = (Button)layout.findViewById(R.id.btn_error_positive);   
btnPositiveError.setTypeface(m_facedesc);
            
start_dialog.setView(layout);
            
final AlertDialog alert = start_dialog.create();
alert.show();
            
btnPositiveError.setOnClickListener(new Button.OnClickListener()
{
    public void onClick(View v) 
    {
        alert.dismiss();
    }
});

ScrrenShot

enter image description here

like image 408
AndroidDev Avatar asked Dec 27 '22 10:12

AndroidDev


2 Answers

Without creating a custom background drawable and adding a special style just add

one line to your code:

dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);

More About Dialogs :

Dilaogs

like image 189
sravan Avatar answered Jan 10 '23 05:01

sravan


Change this line of code

AlertDialog.Builder start_dialog = new AlertDialog.Builder(this);

to

AlertDialog.Builder start_dialog = new AlertDialog.Builder(this).setInverseBackgroundForced(true);

you will be all set

like image 35
MohammadReza Avatar answered Jan 10 '23 06:01

MohammadReza