Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Change custom AlertDialog background

dialog layout xml:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/root_view"
     android:padding="3dp"
     android:background="@android:color/white"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content" >

     //...content...

 </TableLayout>

dialog implementation in map overlay when tapped on pushpin:

AlertDialog.Builder builder;

LayoutInflater inflater = (LayoutInflater) context.getSystemService(Service.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.map_kap_dialog,
                    (ViewGroup) mapView.findViewById(R.id.root_view));

//prepare info to show...
//info prepared

//other preparations stuff
builder = new AlertDialog.Builder(context);
builder.setView(layout);
dialog = builder.create();
dialog.setInverseBackgroundForced(true);
dialog.setCanceledOnTouchOutside(true);
//show it
dialog.show();

and what I see when test it:

enter image description here

So I want that light grey background around dialog box (around square white space) change to white, so it won't look that ugly. Can anyone help me?

like image 386
Paulius Vindzigelskis Avatar asked Feb 27 '26 23:02

Paulius Vindzigelskis


1 Answers

I had the same problem, I managed to fix it using a custom dialog like this:

public class CustomDialog extends Dialog {
    public CustomDialog(Context context, View view) {
        super(context);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(view);
        getWindow().getDecorView().setBackgroundResource(android.R.color.transparent);
    }
}
like image 139
Caner Avatar answered Mar 01 '26 13:03

Caner