AndroidDev
AndroidDev

Reputation: 4559

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

Upvotes: 4

Views: 6270

Answers (5)

Reza
Reza

Reputation: 4753

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

Upvotes: 2

G. Kh.
G. Kh.

Reputation: 306

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.

Upvotes: 0

Satheesh
Satheesh

Reputation: 1730

Just you insert

Dialog start_dialog = new Dialog(this);

instead of this

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

Upvotes: 0

sravan
sravan

Reputation: 5333

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

Upvotes: 8

Hardik4560
Hardik4560

Reputation: 3220

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.

Upvotes: 0

Related Questions