我已通过以下代码创建了自定义alertdialog:
AlertDialog.Builder builder; AlertDialog alertDialog; LayoutInflater inflater = (LayoutInflater)ActivityName.this.getSystemService(LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.custom_layout,(ViewGroup)findViewById(R.id.layout_root)); builder = new AlertDialog.Builder(getParent()); builder.setView(layout); alertDialog = builder.create(); alertDialog.show();
问题是弹出窗口被默认的Dialog背景包围,该背景具有自己的标题空白空间(因为标题未设置).我该如何删除它.我试过通过ContextThemeWrapper来设置自定义样式
builder = new AlertDialog.Builder(new ContextThemeWrapper(getParent(),R.style.CustomDialogTheme));
但它不起作用.我怎么做?!!!提前致谢.
自定义样式xml如下:
<style name="CustomDialogTheme" parent="android:style/Theme.Dialog.Alert"> <item name="android:windowIsFloating">false</item> <item name="android:windowNoTitle">true</item> </style>
解决方法
使用以下
Dialog dialog = new Dialog(this,android.R.style.Theme_Translucent_NoTitleBar);
扩充您的布局并将视图设置为对话框和内容
dialog.setContentView(view);