4

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

iknow
  • 8,358
  • 12
  • 41
  • 68
AndroidDev
  • 4,521
  • 24
  • 78
  • 126
  • I have removed backgrounds doing this: http://stackoverflow.com/questions/8051581/how-to-remove-border-from-dialog. These questions could probably me merged – quinestor Oct 30 '12 at 07:11

5 Answers5

8
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

sravan
  • 5,303
  • 1
  • 31
  • 33
  • it clears all the background and not only the border! Anyway, it works for me, I use a color for the dialog Layour. Good! – Seraphim's Nov 12 '13 at 13:30
  • Best answer for this problem, dont know why people are suggesting creating a custom theme for this problem. – Utsav Gupta Oct 03 '16 at 15:49
2

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

Rez
  • 4,501
  • 1
  • 30
  • 27
0

Just you insert

Dialog start_dialog = new Dialog(this);

instead of this

AlertDialog.Builder start_dialog = new AlertDialog.Builder(this);
Satheesh
  • 1,722
  • 25
  • 35
0

I also had this problem. It's better to use Dialog instead of AlertDialog. That's my solution:

Dialog dialog = new Dialog(getActivity(), R.style.Dialog_No_Border);
dialog.setContentView(R.layout.some_dialog);

Contents of some_dialog.xml

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="250dp"
        android:layout_height="350dp"
        android:orientation="vertical"
        android:background="@drawable/some_dialog_background">

        <TextView
           ...
       />

        <Button
           ...
       />

    </LinearLayout>

styles.xml

<style name="Dialog_No_Border" parent="@android:style/Theme.Dialog">
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowBackground">@color/transparent_color</item>
</style>

So, finally I have my custom dialog with background without borders.

G. Kh.
  • 196
  • 1
  • 12
0

Use Dialog class instead of AlertDialog

for eg - Dialog d = new Dialog(context, android.R.style.Theme_Translucent);

use setContentView instead of setView.

And set its theme to transparent.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Hardik4560
  • 3,202
  • 1
  • 20
  • 31
  • I have used that..but thing is that it make the dialog fullscreen..so is there any option to prevent it form fullscreen – AndroidDev Nov 19 '11 at 10:36