Android:Custom AlertDialog

Iro*_*som 6 android android-alertdialog

我已通过以下代码创建了自定义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();
Run Code Online (Sandbox Code Playgroud)

问题是弹出窗口被默认的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>
Run Code Online (Sandbox Code Playgroud)

这是模拟器上的输出

jee*_*eet 16

使用以下

Dialog dialog = new Dialog(this, android.R.style.Theme_Translucent_NoTitleBar);
Run Code Online (Sandbox Code Playgroud)

扩充您的布局并将视图设置为对话框和内容

dialog.setContentView(view);
Run Code Online (Sandbox Code Playgroud)


Nag*_*ddy 7

AlertDialog dialog = new AlertDialog.Builder(this)
.setView(getLayoutInflater().inflate(R.layout.custom_dialog, null))
.create();
Run Code Online (Sandbox Code Playgroud)

为了侦听UI事件:

View view = getLayoutInflater().inflate(R.layout.custom_dialog, null);
Button btn = (Button)view.findViewById(R.id.the_id_of_the_button);
btn.setOnClickListener(blah blah);
AlertDialog dialog = new AlertDialog.Builder(this)
  .setView(view)
  .create();
Run Code Online (Sandbox Code Playgroud)