Question

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.

Was it helpful?

Solution

Try this, and let me know what happen.

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

OTHER TIPS

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"));
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top