I want to make a part of message text in Bold in AlertDialog.
I tried:
adding <b> </b> tag
in strings.xml
but nothing positive.
i have also used Html.fromHtml("<b>"+getString(R.string.ittformulanote)+"</b>")
i have also been to stackoverflow.com but no positive result.
Below my Code:
showDialog(getActivity(),"Sample",Html.fromHtml("<b>"+getString(R.string.ittformulanote)+"</b>")+"\n\n"+));
public static void showDialog(Context mContext, String Title,
String Description) {
final AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
dialog.setTitle(Title);
// dialog.setMessage((Html.fromHtml("<b>"+Description+"</b>")));
dialog.setMessage(Description);
dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
// TODO Auto-generated method stub
}
});
//
AlertDialog alert=dialog.create();
// dialog.show();
alert.show();
}
This page describes how to add HTML formatting to resource strings.
Their example seems to help if you are having trouble with formatting strings:
Store your styled text resource as an HTML-escaped string:
<resources>
<string name="welcome_messages">Hello, %1$s! You have <b>%2$d new messages</b>.</string>
</resources>
In this formatted string, a element is added. Notice that the opening bracket is HTML-escaped, using the < notation.
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(Html.fromHtml("<b>"+getString(R.string.ittformulanote)+"</b>"));
builder.setNeutralButton("OK", new OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
}
});
AlertDialog alert = builder.create();
alert.show();
Please Try this code..Its working fine
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