Skip to content Skip to sidebar Skip to footer

How To Change The Background Of The Custom Alert Dialog

I have a custom alert dialog, in which i set a list view and its background is white. But i am getting a view like this. This is the screenshot which is fits entire screen. Dialo

Solution 1:

ContextmContext= getApplicationContext(); 
Dialogdialog=newDialog(mContext,android.R.style.Theme_Translucent_NoTitleBar);
dialog.setContentView(R.layout.custom_dialog); 
dialog.show();

the above code will generate a transparent dialog box. So your listviews background will be the only background for the dialog box.

Solution 2:

 AlertDialog.BuilderscreenDialog=newAlertDialog.Builder(AndroidCaptureScreen.this);
    screenDialog.setTitle("Captured Screen");



    TextViewTextOut=newTextView(AndroidCaptureScreen.this);
    TextOut.setText(EditTextIn.getText().toString());
    LayoutParamstextOutLayoutParams=newLayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    TextOut.setLayoutParams(textOutLayoutParams);

    ImageViewbmImage=newImageView(AndroidCaptureScreen.this);
    bmImage.setImageBitmap(bmScreen);
    LayoutParamsbmImageLayoutParams=newLayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
    bmImage.setLayoutParams(bmImageLayoutParams);

    LinearLayoutdialogLayout=newLinearLayout(AndroidCaptureScreen.this);
    dialogLayout.setOrientation(LinearLayout.VERTICAL);
    dialogLayout.addView(TextOut);
    dialogLayout.addView(bmImage);
    screenDialog.setView(dialogLayout);

    screenDialog.setPositiveButton("OK", newDialogInterface.OnClickListener() {
        // do something when the button is clickedpublicvoidonClick(DialogInterface arg0, int arg1) {

         }
        });
    screenDialog.show();
   }

Solution 3:

Get the parent view layout and set its background :)

Solution 4:

This will make it work :

in the Listview add this

android:cachecolorhint="#00000000"

Solution 5:

In my case ,i got the desire output by using this code snippet :

Dialogdialog2=newDialog(Activity.this);
ListViewmodeList=newListView(Activity.this);
AlertDialog.Builderbuilder=newAlertDialog.Builder(Activity.this);


 String[] stringArray = newString[] { "No results" };

  ArrayAdapter<String> modeAdapter = newArrayAdapter<String>(Activity.this, R.layout.list_main, R.id.item_subtitle, stringArray);
  modeList.setAdapter(modeAdapter);

 builder.setView(modeList);
 dialog2 = builder.create();
 dialog2.show();

And in the list_main.xml ,set the background color white :

<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"android:padding="7dp"android:background="#ffffff"></LinearLayout>

For custom adapter :

    builder.setTitle(" title");
            MySimpleAdapter adapter = newMySimpleAdapter(Activity.this, data , R.layout.list_main, 
                    new String[] { "name", "distance" ,"phone","web"}, 
                    newint[] { R.id.item_title, R.id.item_subtitle ,R.id.item_subtitle1 ,R.id.item_subtitle2});
            modeList.setAdapter(adapter);

Post a Comment for "How To Change The Background Of The Custom Alert Dialog"