Set custom font (TypeFace) in dialog in Android

obrien picture obrien · Nov 21, 2011 · Viewed 7.3k times · Source

I'd like to change the font in textview which is in dialog:

dialog = new Dialog(MyActivity.this);
dialog.setContentView(R.layout.my_dialog);
dialog.setCancelable(true);
((TextView)findViewById(R.id.dialog_box_title_text)).setTypeface(Typeface.createFromAsset(getAssets(), "font.ttf"));

But every time I get the runtime exception:

E/AndroidRuntime(4475): java.lang.IllegalStateException: Could not execute method of the activity

Do you have any idea what is wrong? Because normally it works fine. Problem is only when try to change the font in dialog.

Answer

user370305 picture user370305 · Nov 21, 2011

Try this, and let me know what happen.

((TextView)dialog.findViewById(R.id.dialog_box_title_text)).setTypeface(Typeface.createFromAsset(getAssets(), "font.ttf"));