材料成分确认对话框

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

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

Confirmation Dialog

我已经安装了材料成分库,并以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似乎没有能力设置此属性。

android android-alertdialog material-components-android
1个回答
0
投票

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

例如:

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

使用长消息,您可以获得标题和按钮:

enter image description here

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

© www.soinside.com 2019 - 2024. All rights reserved.