Right justify text in AlertDialog

前端 未结 6 1086
逝去的感伤
逝去的感伤 2020-12-06 04:52

Is it possible to right-justify the text in an AlertDialog\'s title and message?

I am showing Hebrew messages but they are showing up left justified.

6条回答
  •  生来不讨喜
    2020-12-06 05:43

    For setting layout direction of alert dialog to RTL you can use OnShowListener method. after setting title , message , .... use this method.

    dialog = alertdialogbuilder.create();
    
            dialog.setOnShowListener(new DialogInterface.OnShowListener() {
                @Override
                public void onShow(DialogInterface dlg) {
                    dialog.getButton(Dialog.BUTTON_POSITIVE).setTextSize(20); // set text size of positive button
                    dialog.getButton(Dialog.BUTTON_POSITIVE).setTextColor(Color.RED); set text color of positive button
    
                    dialog.getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL); // set title and message direction to RTL
                }
            });
            dialog.show();
    

提交回复
热议问题