我在alertDialog中有一个4行文本,我想集中对齐它,而不提供任何自定义布局。这是可能的。
答案 0 :(得分:7)
你可以做到。通过在代码中设置标准对话框的消息文本元素的重力来居中对齐标准AlertView对话框,如下所示:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Title");
builder.setMessage("Message");
builder.setPositiveButton("OK", null);
AlertDialog dialog = builder.show();
// the following line gets a handler to the message element inside the dialog.
TextView messageText = (TextView)dialog.findViewById(android.R.id.message);
// and now all that is needed is changing the gravity ...
messageText.setGravity(Gravity.CENTER);