How To Align Alert Dialog Buttons To The Left?
I want to create an alert dialog with ltr buttons. but it seems like we can't access positive button details.
this answer was for aligning buttons to center, but I want to align it to the left.
I just checked stack and didn't find anything that covers this.i don't want to create custom_layout.xml for dialog.
Answer
This is the answer from the link you posted. You need to change the weight of the layout params from 10 to -10 to go from center to left.
AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).create();
alertDialog.setTitle("Title");
alertDialog.setMessage("Message");
alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDialog.show();
Button btnPositive = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
Button btnNegative = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) btnPositive.getLayoutParams();
//Changing the weight to negative pushes it to the left.
layoutParams.weight = -10;
btnPositive.setLayoutParams(layoutParams);
btnNegative.setLayoutParams(layoutParams);
Hope it helps!
More information: Now that I understand the question, no sadly you cannot change the order or the buttons. The order is NEGATIVE - NEUTRAL - POSITIVE. But once you have the button you can choose whatever to do with. For instance, you can use the negative button as the positive, by just renaming it in one line.
Related Questions
- → should I choose reactjs+f7 or f7+vue.js?
- → Phonegap Android write to sd card
- → Local reference jquery script in nanohttpd (Android)
- → Click to navigate on mobile devices
- → How to allow api access to android or ios app only(laravel)?
- → Access the Camera and CameraRoll on Android using React Native?
- → React native change listening port
- → What is the default unit of style in React Native?
- → Google play market autocomplete icon
- → Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView`
- → Using Laravel with Genymotion
- → react native using like web-based ajax function
- → react native pdf View