如何更改自定义警报对话框的背景

发布于 2024-12-09 18:51:56 字数 812 浏览 0 评论 0原文

我有一个自定义警报对话框,其中我设置了一个列表视图,其背景为白色。

但我得到了这样的看法。

image

这是适合整个屏幕的屏幕截图。

 Dialog d = new Dialog(context,android.R.style.Theme_Translucent_NoTitleBar);       
        CustomDialogListAdapter customDialogAdapter;
        ListView customList = new ListView(context);
        customList.setLayoutParams(new LayoutParams(LayoutParams.FILL_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();

提前致谢..!

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.

image

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.FILL_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..!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

Context mContext = getApplicationContext(); 
Dialog dialog = new Dialog(mContext,android.R.style.Theme_Translucent_NoTitleBar);
dialog.setContentView(R.layout.custom_dialog); 
dialog.show();

上面的代码将生成一个透明的对话框。因此,您的列表视图背景将是对话框的唯一背景。

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.

橘寄 2024-12-16 18:51:57
 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();
   }
 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();
   }
回忆追雨的时光 2024-12-16 18:51:57

获取父视图布局并设置其背景:)

Get the parent view layout and set its background :)

寻梦旅人 2024-12-16 18:51:57

这将使它工作:

在列表视图中添加此

android:cachecolorhint="#00000000"

This will make it work :

in the Listview add this

android:cachecolorhint="#00000000"

多情癖 2024-12-16 18:51:57

就我而言,我通过使用以下代码片段获得了所需的输出:

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();

并在 list_main.xml 中,将背景颜色设置为白色:

<?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>

对于自定义适配器:

    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);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文