android 4.4 Kitkat 上未显示 AlertDialog 分隔符

AlertDialog divider is not showing on android 4.4 Kitkat

我有四个项目(字符串数组)的警告对话框,我想在每个项目和第一个分隔线之间添加不同颜色的分隔线,我在 android 4.4 kitkat 上看到它是这样的

这是我的警报对话框代码

AlertDialog.Builder dialog = new AlertDialog.Builder(this);
            dialog.setTitle(getString(R.string.choose_layout));

            String[] recyclerViewLayouts = getResources().getStringArray(R.array.RecyclerViewLayouts);
            SharedPreferences.Editor editor = sharedPreferences.edit();

            dialog.setItems(recyclerViewLayouts, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int index) {


                    }
                }
            });
            dialog.create();
            dialog.show();

我尝试使用以下代码创建它,但也没有显示

AlertDialog alertDialog = builder.create();

ListView listView = alertDialog.getListView();

listView.setDivider(new ColorDrawable(Color.GRAY));

listView.setDividerHeight(1);

alertDialog.show();

[已解决]

找了好几个小时发现问题是我用了androidx lib androidx.appcompat.app.AlertDialog的AlertDialog 还不支持自动添加分隔符,我是在我改成它之后应该使用 android.app.AlertDialog.Builder 分隔符再次显示

更新后的代码

android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(this);

            builder.setTitle(getString(R.string.choose_layout));

            String[] recyclerViewLayouts = getResources().getStringArray(R.array.RecyclerViewLayouts);
            SharedPreferences.Editor editor = sharedPreferences.edit();


            builder.setItems(recyclerViewLayouts, (dialog, index) -> {

                }
            });

            android.app.AlertDialog alertDialog = builder.create();
            alertDialog.show();