I\'m new with android.
Currently I want to show an AlertDialog
box with \'OK\' & \'Cancel\' buttons.
The default is PositiveButton: Left, Ne
A really simple way to shift the buttons of the AlertDialog
to the right hand side is to hide the leftSpacer
, a LinearLayout
within the core XML which handles the default layout.
// Fetch the PositiveButton
final Button lPositiveButton = lDialog.getButton(AlertDialog.BUTTON_POSITIVE);
// Fetch the LinearLayout.
final LinearLayout lParent = (LinearLayout) lPositiveButton.getParent();
// Ensure the Parent of the Buttons aligns it's contents to the right.
lParent.setGravity(Gravity.RIGHT);
// Hide the LeftSpacer. (Strict dependence on the order of the layout!)
lParent.getChildAt(1).setVisibility(View.GONE);