【发布时间】:2016-09-29 10:33:39
【问题描述】:
我被margin 和padding 标题为AlertDialog.Builder 的问题困住了,我正在做的是我想要center 中的标题所以我使用setCustomTitle 我能够这样做但卡住了它的边距和填充。我不想显示不需要的填充,而且我想为标题设置一些上边距,我正在使用LinearLayout.LayoutParams,但它没有效果。请建议如何处理它。谢谢
代码:
dialog = new AlertDialog.Builder(context, R.style.DialogTheme);
TextView title = new TextView(context);
title.setTextColor(ContextCompat.getColor(context, R.color.black));
title.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
title.setTypeface(Typeface.DEFAULT_BOLD);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(0, 20, 0, 0);
title.setLayoutParams(lp);
title.setText("Dialog");
title.setGravity(Gravity.CENTER);
dialog.setCustomTitle(title);
dialog.setMessage("Dialog box with custom title view ");
dialog.setCancelable(false);
dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
dialog.show();
【问题讨论】:
-
看起来不错!我没有看到填充有任何问题。如果你想在
dialogsetContentView()中使用重力概念,你可以居中文本! -
@utkarshdubey 我不想在对话框标题和默认情况下出现的对话框消息之间有太多填充
标签: android android-alertdialog android-dialog