For an alert dialog in Android, how do you make the positive button not have all capital letters. The text is "OK" instead of "Ok".
-
What kind of dialog are you using? Please show your code if you want a proper answer. – Codeman Jul 27 '15 at 21:46
-
@Pheonixblade9 Um... I said alert dialog if you read the question? – Henry Zhu Jul 27 '15 at 21:49
-
Yes, that is why I'm confused. You set the text yourself. There are no default options. – Codeman Jul 27 '15 at 21:50
-
this is a working solution : http://stackoverflow.com/questions/27893840/lollipop-capitalizes-buttons-text-in-my-app/39143743#39143743 – TharakaNirmana Aug 25 '16 at 11:13
6 Answers
The accepted solution above won't work in Lollipop and above. Here's the working solution.
After showing the dialog, I'm setting the button all caps false. Make sure you do it after dialog.show()
. Else, you'll get Null Pointer Exception
.
AlertDialog.Builder builder = new AlertDialog.Builder(MyActivity.this);
builder.setTitle("Title");
builder.setMessage("message");
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//Do Something
}
});
AlertDialog dialog = builder.create();
dialog.show();
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setAllCaps(false);

- 1,205
- 1
- 14
- 33
-
-
-
@KamrujjamanJoy Are you using `androidx.appcompat.app.AlertDialog`? If so, it should be. – David Lee Jul 06 '21 at 01:40
Use the DialogInterface.BUTTON_POSITIVE or DialogInterface.BUTTON_NEGATIVE to customize the action buttons.
val builder = MaterialAlertDialogBuilder(requireContext())
builder.setTitle(getString(R.string.alert_title))
builder.setMessage(getString(R.string.alert_msg))
builder.setPositiveButton(getString(R.string.action_yes)) { _, _ ->
// todo: your action
}
builder.setNegativeButton(getString(R.string.action_no), null)
val dialog = builder.create()
dialog.show()
dialog.getButton(DialogInterface.BUTTON_POSITIVE).isAllCaps = false
dialog.getButton(DialogInterface.BUTTON_NEGATIVE).isAllCaps = false

- 69
- 1
- 6
You can set it to be anything you want - Eg.:
AlertDialog.Builder builder = new AlertDialog.Builder(MyActivity.this);
builder.setTitle("Title");
builder.setMessage("message");
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
return;
}
});
AlertDialog dialog = builder.create();
dialog.show();

- 2,689
- 1
- 30
- 49
-
No problem. When in doubt, double check the documentation - which can be done online or from your IDE! Also, posting the code you are trying to get work always helps us direct your/our efforts better! – jesses.co.tt Jul 27 '15 at 21:51
-
1this thing is not gonna work on lolipop and version greater than it. – satya prakash Aug 23 '17 at 09:21
-
-
Starting with Android 5.0, Buttons automatically have their text capitalized. you can't set capitaliztion in builder directly. – Burak Senel Feb 11 '22 at 10:08
using androidx.appcompat.app.AalertDialog fixed for me.
-
1Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 27 '22 at 06:48
its late, but it could help other who visits.
To change the button text case, from all capitals to small case, usual method such as
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setAllCaps(false);
this will not work with the alert builder anymore, upon exploring alert dialog code, I found Buttons used for it, and as default it will show capital text.
To set, we need to add style while creating the alert dialog. Follow below steps for the same.
- In your theme.xml or style.xml add below style.
<style name="custom_alert_button_text" parent="ThemeOverlay.MaterialComponents.Dialog.Alert"> <item name="android:textAllCaps">false</item> <item name="android:textSize">@dimen/_13ssp</item> <item name="android:textAppearance">?textAppearanceFiraSansBoldBlue34Text</item> </style>
- While building the alert dialog, add style to your alert dialog as follow.
val alertBox = AlertDialog.Builder(context, R.style.custom_alert_button_text) alertBox.setCancelable(false) alertBox.setMessage("Your message for dialog") alertBox.setNegativeButton( "No" ) { dialog, _ -> dialog.dismiss() } alertBox.setPositiveButton( "Yes" ) { dialog, _ -> dialog.dismiss() //your action to perform on yes tap. } alertBox.show()
This way, the positive and negative buttons text cases can be changed.
I am using this method to change the text cases for alert dialog with builder.
Hope it helps!

- 111
- 2
- 5