在Android 4.4 Kitkat上没有显示AlertDialog分隔符

问题描述 投票:0回答:1

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

enter image description here

这是我的警报对话框代码

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();
android android-layout android-alertdialog android-theme android-styles
1个回答
0
投票

[Solved]

经过几个小时的搜索,我发现问题是我使用了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();
© www.soinside.com 2019 - 2024. All rights reserved.