Violin Nz Violin Nz - 5 months ago 39
Android Question

How to center text in Alert Dialog Builder?

I'm trying to center some text in a default Alert Dialog Builder
Here's my code so far, but it defaults to the left.

new AlertDialog.Builder(getActivity())
.setTitle("Well done!")
.setMessage("Message centered????")

.setPositiveButton("OK",
new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog,
int which) {
// TODO Auto-generated method stub

}
})

.setIcon(R.drawable.img_ok)
.show();

}

Answer

Instead of setting the message, use AlertDialog.Builder.setView(View) with a View with centred text