我被卡住了margin
和padding
問題的標題AlertDialog.Builder
,我正在做的是我想要的標題在center
所以我使用setCustomTitle
我能夠這樣做,但堅持與保證金和填充它。我不想要不必要的填充顯示,也想設置一些頂部邊緣標題,我使用LinearLayout.LayoutParams
,但它沒有效果。請建議怎樣做才能處理it.thanks如何設置AlertDialog自定義標題頂部邊距並刪除不需要的填充?
代碼:
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();
看起來不錯!我在padding中看不到任何問題。如果你想在'dialog''setContentView()'中使用重力概念,可以將文本**置中**! –
@utkarshdubey我不想在對話框標題和對話框消息之間有很多填充,這是默認結果 –