i have to align text by middle in android alertdialog. but i cannot find way... anyone knows how to this?
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();
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With