如何更改自定义警报对话框的背景
我有一个自定义警报对话框,其中我设置了一个列表视图,其背景为白色。
但我得到了这样的看法。
这是适合整个屏幕的屏幕截图。
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.
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
上面的代码将生成一个透明的对话框。因此,您的列表视图背景将是对话框的唯一背景。
the above code will generate a transparent dialog box. So your listviews background will be the only background for the dialog box.
获取父视图布局并设置其背景:)
Get the parent view layout and set its background :)
这将使它工作:
在列表视图中添加此
android:cachecolorhint="#00000000"
This will make it work :
in the Listview add this
android:cachecolorhint="#00000000"
就我而言,我通过使用以下代码片段获得了所需的输出:
并在 list_main.xml 中,将背景颜色设置为白色:
对于自定义适配器:
In my case ,i got the desire output by using this code snippet :
And in the list_main.xml ,set the background color white :
For custom adapter :