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.
Try this, and let me know what happen.
((TextView)dialog.findViewById(R.id.dialog_box_title_text)).setTypeface(Typeface.createFromAsset(getAssets(), "font.ttf"));
For a DialogFragment
this will work (I'm targeting SDK 19, and I have minSDK 14) as long as you put the font file in your assets()
folder.
So if you are running ice cream sandwich (ICS) and later try this :
@Override public void onActivityCreated(Bundle savedInstanceState)
{
// Call to the Super Class, performing the default behavior
super.onActivityCreated(savedInstanceState);
// Change the Dialog Title Text Typeface
((TextView)getDialog().findViewById(android.R.id.title)).setTypeface(
Typeface.createFromAsset(getActivity().getAssets(),"Roboto-Thin.ttf"));
}
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