Reputation: 1812
I have a class named CommonCode that is used for stocking all methods I frequently need.
One of those methods is creating a toast with a custom layout. I want to give the TextView in that toast a custom font so I use a TypeFace. When trying to get the custom font from my assets folder, it goes wrong.
I get the issue "The method getAsssets() is undefined for the type Context".
Here's my code: the CommonCode class
public class CommonCode {
public static void showToast(String toastString, Context context, View view) {
LayoutInflater inflater = LayoutInflater.from(context);
View layout = inflater.inflate(R.layout.toast_layout, (ViewGroup) view);
ImageView image = (ImageView) layout.findViewById(R.id.toastImage);
image.setImageResource(R.drawable.android);
TextView text = (TextView) layout.findViewById(R.id.toastText);
Typeface type = Typeface.createFromFile(context.getAsssets(), "fonts/aircruiser.ttf");
text.setTypeface(type);
text.setText(toastString);
Toast toast = new Toast(context);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_SHORT);
toast.setView(layout);
toast.show();
}
}
Thanks guys!
Upvotes: 2
Views: 5061
Reputation: 132972
use getAssets()
instead of getAsssets(),
:
Typeface type= Typeface.createFromAsset(context.getAssets(), "fonts/aircruiser.ttf");
text.setTypeface(type);
Upvotes: 3