Android 如何设置吐司的字体?

Android 如何设置吐司的字体?,android,toast,Android,Toast,我可以像这样为我的文本视图设置自定义字体 Typeface typeface = Typeface.createFromAsset(context.getAssets(),"fonts/akshar.ttf"); setTypeface(typeface); 如何将相同的内容设置为默认Toast,以便能够在Toast消息中呈现区域设置文本。我能设定重力、持续时间,但不能设定字体 提前感谢。您可以通过以下方式创建自定义的Toast: LayoutInflater inflater = getL

我可以像这样为我的文本视图设置自定义字体

Typeface typeface = Typeface.createFromAsset(context.getAssets(),"fonts/akshar.ttf");
setTypeface(typeface);
如何将相同的内容设置为默认Toast,以便能够在Toast消息中呈现区域设置文本。我能设定重力、持续时间,但不能设定字体


提前感谢。

您可以通过以下方式创建自定义的Toast:

 LayoutInflater inflater = getLayoutInflater();
    View layout = inflater.inflate(R.layout.toast_layout,
                                   (ViewGroup) findViewById(R.id.toast_layout_root));

    TextView text = (TextView) layout.findViewById(R.id.text);
    text.setText("Hello! This is a custom toast!");
    Typeface typeface = Typeface.createFromAsset(context.getAssets(),"fonts/akshar.ttf");
    text.setTypeface(typeface);
    Toast toast = new Toast(getApplicationContext());
    toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.setView(layout);

toast.show();
有关如何创建自定义Toast的更多详细信息,请参见Toast has a method,这样您就可以设置TextView的字体,并使用

toast.setView(textview);

面向对象。。。在自定义Toast中将字体设置为文本视图,解决了我的问题。很简单的事情