开发者

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.

How to change the background of the custom alert dialog

This is the screenshot which is fits entire screen.

 Dialog d = new Dialog(context,android.R.style.Theme_Translucent_NoTitleBar);       
        CustomDialogListAdapter customDialogAdapter;
        ListView customList = new ListView(context);
        customList.setLayoutParams(new LayoutParams(LayoutParams.F开发者_运维知识库ILL_PARENT,LayoutParams.WRAP_CONTENT));
        customList.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        customDialogAdapter = new CustomDialogListAdapter(context,PaymentInfo.creditCardTypes, type);
        customList.setAdapter(customDialogAdapter);
        customList.setBackgroundColor(Color.WHITE);
        d.setContentView(customList);
        d.show();

Thanks in advance..!


Context mContext = getApplicationContext(); 
Dialog dialog = new Dialog(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.


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



    TextView TextOut = new TextView(AndroidCaptureScreen.this);
    TextOut.setText(EditTextIn.getText().toString());
    LayoutParams textOutLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    TextOut.setLayoutParams(textOutLayoutParams);

    ImageView bmImage = new ImageView(AndroidCaptureScreen.this);
    bmImage.setImageBitmap(bmScreen);
    LayoutParams bmImageLayoutParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
    bmImage.setLayoutParams(bmImageLayoutParams);

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

    screenDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        // do something when the button is clicked
        public void onClick(DialogInterface arg0, int arg1) {

         }
        });
    screenDialog.show();
   }


Get the parent view layout and set its background :)


This will make it work :

in the Listview add this

android:cachecolorhint="#00000000"


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

Dialog dialog2 = new Dialog(Activity.this);
ListView modeList = new ListView(Activity.this);
AlertDialog.Builder builder = new AlertDialog.Builder(Activity.this);


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

  ArrayAdapter<String> modeAdapter = new ArrayAdapter<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"?><LinearLayout xmlns: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 = new MySimpleAdapter(Activity.this, data , R.layout.list_main, 
                    new String[] { "name", "distance" ,"phone","web"}, 
                    new int[] { R.id.item_title, R.id.item_subtitle ,R.id.item_subtitle1 ,R.id.item_subtitle2});
            modeList.setAdapter(adapter);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜