我有四个项目的警告对话框(字符串数组),我想在每个项目和第一个分隔符之间添加不同颜色的分隔符,我在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();