user3753721
user3753721

Reputation:

Move Dialog Message/Title to right side

Inside my app I have simple dialog but I have problem to move message/title to right corner side. I found a solution to move to right but distance is hardcoded (I need to tell how much char to right) it looks like :

builder.setTitle(String.format("%20s","1/10")); 

where "%20s" tells that it moves to right for 20chars. There is an option to do it in other way where I don't need to tell how much to right just it take place in right corner/end of line ? I want to have this message in right corner in all screen sizes devices.

Upvotes: 1

Views: 158

Answers (1)

Kaushal28
Kaushal28

Reputation: 5555

Try this out:

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("My Title");
builder.setMessage("your message");
builder.setPositiveButton("OK", null);

AlertDialog dialog = builder.show();
TextView messageText = (TextView)dialog.findViewById(android.R.id.message);
messageText.setGravity(Gravity.CENTER);
dialog.show();

If you want right alignment, just change messageText.setGravity(Gravity.CENTER); to messageText.setGravity(Gravity.RIGHT);.

Hope this helps :)

Upvotes: 1

Related Questions