I tried to change AlertDialog font by used this function
private void saveDialog(){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(res.getString(R.string.dialog_title))
.setMessage(res.getString(R.string.dialog_saveconfirm))
.setCancelable(false)
.setNegativeButton(res.getString(R.string.dialog_cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
})
.setPositiveButton(res.getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//do some thing
});
AlertDialog alert = builder.create();
alert.show();
TextView tit = (TextView) alert.findViewById(android.R.id.title);
TextView msg = (TextView) alert.findViewById(android.R.id.message);
Button btn2 = alert.getButton(DialogInterface.BUTTON_NEGATIVE);
Button btn1 = alert.getButton(DialogInterface.BUTTON_POSITIVE);
tit.setTypeface(UtiliShare.getTf());
msg.setTypeface(UtiliShare.getTf());
btn1.setTypeface(UtiliShare.getTf());
btn2.setTypeface(UtiliShare.getTf());
}
When I call function in Activity I had 02-25 17:59:04.759: E/AndroidRuntime(1014): java.lang.NullPointerException
for tit
when set typeface but when I remove tit
dialog work good.
I think error in TextView tit = (TextView) alert.findViewById(android.R.id.title);
it is return null.
How can I solve this??
Update This link contain answer of my question Answer
Thanks to Sam
In order to alter textviews the way you want, I'd recommend using a custom layout for dialogs. Have a look at
http://developer.android.com/guide/topics/ui/dialogs.html#CustomLayout
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