Center message in android dialog box

前端 未结 8 854
野趣味
野趣味 2020-11-29 01:53

I want the message text within my dialog box to be center aligned.

8条回答
  •  爱一瞬间的悲伤
    2020-11-29 02:07

    Create your own TextView object and then supply it to popup builder as View:

    AlertDialog.Builder popupBuilder = new AlertDialog.Builder(this);
    TextView myMsg = new TextView(this);
    myMsg.setText("Central");
    myMsg.setGravity(Gravity.CENTER_HORIZONTAL);
    popupBuilder.setView(myMsg);
    

    You can control all other text parameters (style, color, size ...). To control margins you may programatically create LinearLayout, set LayoutParams, and then put TextView into it.

提交回复
热议问题