【问题标题】:AlertDialog divider is not showing on android 4.4 Kitkatandroid 4.4 Kitkat 上未显示 AlertDialog 分隔符
【发布时间】:2019-04-08 08:44:07
【问题描述】:

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

【问题讨论】:

    标签: android android-layout android-alertdialog android-theme android-styles


    【解决方案1】:

    [已解决]

    经过几个小时的搜索,我发现问题是我使用了 androidx lib androidx.appcompat.app.AlertDialog 的 AlertDialog 尚不支持自动添加分隔符,我应该使用 @987654322 @ 在我改成它之后,分隔线再次显示

    更新后的代码

    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();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-14
      • 1970-01-01
      • 2013-12-05
      • 2021-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-08
      相关资源
      最近更新 更多