I have created an Alert Dialog, and i want to know how to set the gravity of the message as center:
Dialog dialog;
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(completedMessage());
dialog = builder.create();
here is the completedMessage() method:
private String completedMessage() {
String[] messages = getResources().getStringArray(R.array.success);
String completeMsg = "\n";
int messagei= (int) Math.floor(Math.random() * messages.length);
completeMsg += messages[messagei];
return completeMsg;
}
and here is the arrays.success:
<string-array name="success">
<item>You got it!</item>
<item>Success!</item>
<item>Done!</item>
<item>Great job, young Padawan.</item>
</string-array>
no title, no buttons, no list, just the message, and i want to show it centered, no matter the string length.
I have tried:
Dialog dialog;
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(completedMessage());
dialog = builder.show();
TextView messageView = (TextView)dialog.findViewById(android.R.id.message);
messageView.setGravity(Gravity.CENTER_VERTICAL);
But this changes nothing.
Btw, the message shows in the box like having a padding on top and left, but no padding on the bottom nor right.