Set AlertDialog Positive Button Text to be Bold
android, android-alertdialog, android-dialog
Solution
Instead of setting the button text to be `"add"`, set it to be `Html.fromHtml("<b><i>add</i></b>")`
So for with your code:
Change these lines:
builder.setPositiveButton(R.string.ok_button, null);
// and
builder.setNegativeButton(R.string.cancel_button, null);
To these lines:
builder.setPositiveButton(Html.fromHtml("<b><i>" + getString(R.string.ok_button) + "</i><b>"), null);
// and
builder.setNegativeButton(Html.fromHtml("<b><i>" + getString(R.string.cancel_button) + "</i><b>"), null);
OR
you could modify the Strings in your `strings.xml` file.
So for example, if your strings looked like this:
<string name="ok_button">add</string>
<string name="cancel_button">cancel</string>
you could change them to this:
<string name="ok_button"><b><i>add</i></b></string>
<string name="cancel_button"><b><i>cancel</i></b></string>
but
you still are referencing your Strings resources incorrectly. Instead of `R.string.ok_button`, because that returns an int, you would have to use `getString(R.string.ok_button)`
So you would have to change these lines:
builder.setPositiveButton(R.string.ok_button, null);
// and
builder.setNegativeButton(R.string.cancel_button, null);
To these lines:
builder.setPositiveButton(getString(R.string.ok_button), null);
// and
builder.setNegativeButton(getString(R.string.cancel_button), null);
Problem
Here is my code. ``` AlertDialog.Builder builder = new AlertDialog.Builder(this); LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); final View vi = inflater.inflate(R.layout.group_dialog_layout,null); builder.setView(vi); TextView txtNewGroupEntry = (TextView) vi.findViewById(R.id.txtGroupRename); if(isNew==true){ builder.setTitle("New Group"); txtNewGroupEntry.setText(R.string.new_group_instruction); } builder.setPositiveButton(R.string.ok_button, null); builder.setNegativeButton(R.string.cancel_button, null); AlertDialog dialog = builder.create(); dialog.show(); Button okButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE); ``` I have an alert dialog with an add button and a cancel button. I want both of the button's text to be bold and italic. How can I do it?