【问题标题】:Material Components Confirmation Dialog材料成分确认对话框
【发布时间】:2019-06-10 14:43:34
【问题描述】:

如何实现下图对话框中标题和按钮上可以看到的水平分隔线或标高?

我已经安装了材料组件库并使用dialog documentation作为指导。

代码如下:

MaterialAlertDialogBuilder materialAlertDialogBuilder = new MaterialAlertDialogBuilder(this.getActivity());

LayoutInflater inflater = ((Activity) context).getLayoutInflater();
View view = inflater.inflate(R.layout.dialog_settings, null);

setupView(view);


materialAlertDialogBuilder.setView(view);
materialAlertDialogBuilder.setTitle("Settings");

materialAlertDialogBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener()
{
    @Override
    public void onClick(DialogInterface dialog, int which)
    {

    }
});

materialAlertDialogBuilder.setNegativeButton("CANCEL", new DialogInterface.OnClickListener()
{
    @Override
    public void onClick(DialogInterface dialog, int which)
    {

    }
});

materialAlertDialogBuilder.setCancelable(false);
materialAlertDialogBuilder.create();
materialAlertDialogBuilder.show();

MaterialAlertDialogBuilder 似乎没有设置这个属性的能力。

【问题讨论】:

  • @JeelVankhede 样式不存在
  • @JeelVankhede,不幸的是,上面的图片中没有一种样式
  • 好吧..我的错..只是想帮忙????
  • 请注意,上面的图片应该是一个模型,并不代表Android中的实际原生实现。
  • @Edric 很遗憾,它看起来很酷。想也许我可以使用一种风格,而不必自己做“繁重的工作”

标签: android material-design android-alertdialog material-components-android


【解决方案1】:

只需使用标准的MaterialAlertDialogBuilder
如果您有标题面板、按钮面板和需要可滚动视图的内容,则这是默认行为。

例如:

    CharSequence[] choices = {"Choice1", "Choice2", "Choice3", "Choice1", "Choice2", "Choice3","Choice1", "Choice2", "Choice3","Choice1", "Choice2", "Choice3","Choice1", "Choice2", "Choice3","Choice1", "Choice2", "Choice3"};
    boolean[] choicesInitial = {false, true, false, false, true, false,false, true, false,false, true, false, false, true, false,false, true, false};

    new MaterialAlertDialogBuilder(MainActivity.this)
        .setTitle("Title")
        .setMultiChoiceItems(choices, choicesInitial, null)
        .setPositiveButton("ok", null)
        .setNegativeButton("Cancel", null)
        .show();

使用长消息,带有标题和按钮可以获取:

new MaterialAlertDialogBuilder(AlertDialogActivity.this)
            .setTitle("Title")
            .setMessage(multiLineMessage.toString())
            .setPositiveButton("ok", null)
            .setNegativeButton("Cancel", null)
            .show();

【讨论】:

  • 即使内容不可使用 MaterialAlertDialog 滚动,是否也可以始终显示水平分隔线?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-29
  • 2015-04-16
  • 2020-04-24
  • 2021-11-27
  • 1970-01-01
  • 2021-10-08
相关资源
最近更新 更多