android : how to align message in alertDialog?

前端 未结 8 799

i have to align text by middle in android alertdialog. but i cannot find way... anyone knows how to this?

相关标签:
8条回答
  • 2020-12-15 05:00

    You would have to use one of the constructors provided for AlertDialog in Android, while creating one.

    AlertDialog(Context context, int theme) Construct an AlertDialog that uses an explicit theme.

    This link will help you. Since you want the text to be centered, you would want to give the gravity attribute, the value 'center'.

    0 讨论(0)
  • 2020-12-15 05:00

    Try this - it will do the trick.

    AlertDialog.Builder completeDialog = new AlertDialog.Builder(Main.this);
    
    TextView resultMessage = new TextView(Main.this);
    resultMessage.setTextSize(22);
    resultMessage.setText("Upload completed!");
    resultMessage.setGravity(Gravity.CENTER);
    completeDialog.setView(resultMessage);
    
    completeDialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
    
        @SuppressLint("DefaultLocale")
        public void onClick(DialogInterface dialog, int whichButton) {
            dialog.dismiss();               
        }
    
    });
    
    completeDialog.show();
    
    0 讨论(0)
提交回复
热议问题