AlertDialog.Builder alert = new AlertDialog.Builder(this)
.setMessage("确定吗?").setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
})
.setNegativeButton(R.string.back, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
TextView title = new TextView(this);
title.setGravity(Gravity.CENTER);
title.setBackgroundResource(R.drawable.list);
title.setText("确定");
alert.setCustomTitle(title);
alert.show();
通过使用AlertDialog.Builder的setCustomTitle方法,可以实现AlertDialog标题的居中显示。具体步骤是创建一个自定义布局,设置标题居中,然后将其设置为AlertDialog的标题。
792

被折叠的 条评论
为什么被折叠?



