如何实现下图中对话框的“标题”和“按钮”上可见的水平分隔线或高程?
我已经安装了材料组件库,并使用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
似乎无法设置此属性。
答案 0 :(得分:0)
只需使用标准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();