Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android : how to align message in alertDialog?

Tags:

android

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

like image 702
coolhex Avatar asked Oct 19 '10 03:10

coolhex


2 Answers

try this

AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("My Title"); builder.setMessage("your message"); builder.setPositiveButton("OK", null); AlertDialog dialog = builder.show(); TextView messageText = (TextView)dialog.findViewById(android.R.id.message); messageText.setGravity(Gravity.CENTER); dialog.show(); 

like image 115
jeevamuthu Avatar answered Sep 30 '22 04:09

jeevamuthu


I know this thread is old but might help some people :D

TextView title = new TextView(this); title.setText("Client details not saved!"); title.setPadding(10, 10, 10, 10); title.setGravity(Gravity.CENTER); // title.setTextColor(getResources().getColor(R.color.greenBG)); title.setTextSize(23);  TextView msg = new TextView(this); msg.setText("You're going to lose all the information if you continue!"); msg.setPadding(10, 10, 10, 10); msg.setGravity(Gravity.CENTER); msg.setTextSize(18);  DialogInterface.OnClickListener onClick = new DialogInterface.OnClickListener() {      public void onClick(DialogInterface dialog, int which) {         if (which == DialogInterface.BUTTON_POSITIVE) {             finish();         }     }  };  Builder builder = new AlertDialog.Builder(this); builder.setCustomTitle(title); builder.setView(msg); builder.setCancelable(true); builder.setPositiveButton("Yes", onClick); builder.setNegativeButton("No", onClick);  AlertDialog dialog = builder.create(); dialog.show(); 
like image 25
Sorin Avatar answered Sep 30 '22 04:09

Sorin