Set right gravity to a message inside a ProgressDi

2019-07-24 08:41发布

问题:

I want to set a right gravity to a message inside my ProgressDialog. I've tried to:

dialog = new ProgressDialog(activity);
dialog.getWindow().setGravity(Gravity.RIGHT);
dialog.setMessage(loadDialogMessage); 

But still the gravity of the message is set to the right. How can I do that ?

回答1:

Something like this should do the trick :

ProgressDialog dialog = new ProgressDialog(getActivity());
dialog.setMessage("42 is the answer to life the universe and everything");
dialog.show();
TextView tvMessage = (TextView)dialog.findViewById(android.R.id.message);
tvMessage.setGravity(Gravity.RIGHT);

I just looked at the source http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.2_r1.1/android/app/ProgressDialog.java#147 and look at the textview's id