android : how to align message in alertDialog?

前端 未结 8 800

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

8条回答
  •  时光取名叫无心
    2020-12-15 04:56

    You can use your custom layout for alert dialog layout. To align default alert dialog layout message center you can do

            AlertDialog alertDialog;
            AlertDialog.Builder builder = new AlertDialog.Builder(context);
            builder.setMessage("hello world");
            alertDialog = builder.show();
            TextView messageText = (TextView) alertDialog.findViewById(android.R.id.message);
            messageText.setGravity(Gravity.CENTER);
    

    Be careful, if you set messageText with findViewById before you call builder.show() you'll get a null pointer exception.

提交回复
热议问题