警报 dailog 选项之间的分隔线

Awa*_*esh 3 android android-alertdialog

我正在使用警报对话框来显示 whatsapp 中的操作。

AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
Run Code Online (Sandbox Code Playgroud)

我正在使用 setItems() 方法提供选项列表

dialog.setItems(options.toArray(new String[options.size()]), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Intent intent = new Intent(mContext, AddTaskActivity.class);
                mContext.startActivity(intent);
            }
        });
Run Code Online (Sandbox Code Playgroud)

但问题是它还显示了不同选项之间的分隔符,如下所示,截图: 在此处输入图片说明

现在的问题是我想隐藏分隔符。任何帮助表示赞赏。提前致谢 :)

yen*_*rah 5

因此,根据这篇文章Alertdialog 默认按钮分隔符删除,会出现问题,因为您的项目在 ListView 中膨胀,布局为 simple_list_item - 其底部是分隔符。解决方案是将分隔线高度设置为 0:

AlertDialog alertDialog = builder.create();
alertDialog.getListView().setDividerHeight(0);
Run Code Online (Sandbox Code Playgroud)

编辑:在 API 21 上测试 - 即使没有添加也没有行。