AlertDialog 不在列表中显示分隔线

AlertDialog does not show dividers on a list

我有这个class:

public class PageDetailInfoView extends FrameLayout {

//few constructors and methods

//method to show an AlertDialog with a list
private void openDialog(){

    List<String> mTags = new ArrayList<String>();
    mTags.add("Item1");
    mTags.add("Item2");
    mTags.add("Item3");
    mTags.add("Item4");
    mTags.add("Item5");
    mTags.add("Item6");

    final CharSequence[] tags = mTags.toArray(new String[mTags.size()]);
    AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
    builder.setTitle("Title");
    builder.setItems(tags, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int item) {
        //do something
        }
    });

    Dialog alertDialogObject = builder.create();
    alertDialogObject.show();


}

警报对话框在调用 openDialog() 后打开,但问题是它不显示项目之间的分隔符。 我想得到这个:
http://2.bp.blogspot.com/-i00d8VG6WsQ/UrGIeyb-8II/AAAAAAAAHwA/8MPWP5qrQ78/s500/alertdialog-with-simple-listview.png

事实上,我明白了,但没有灰色分隔线。
知道为什么吗?

AlertDialog 列表项分隔线颜色更改为:

AlertDialog alertDialogObject = dialogBuilder.create();
ListView listView=alertDialogObject.getListView();  
listView.setDivider(new ColorDrawable(Color.BLUE)); // set color
listView.setDividerHeight(2); // set height 
alertDialogObject.show();

这可能是因为您 运行 您的应用在 Android 5.0+ 上具有 Material 设计。

要获得 "old" 外观,只需使用 Holo 样式构建对话框:

ContextThemeWrapper themedContext = new ContextThemeWrapper(getContext(), android.R.style.Theme_Holo_Light_Dialog_NoActionBar);
AlertDialog.Builder builder = new AlertDialog.Builder(themedContext);
// ... then create your dialog

虽然这对某些用户来说可能看起来很奇怪(尤其是在 Lollipop 和 Marshmallow 上,所以我建议考虑为您的对话框使用自定义视图。