我可以像这样将自定义字体设置为我的文本视图
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); toast.setDuration(Toast.LENGTH_LONG); toast.setView(layout); toast.show();
有关我们如何创建自定义Toast的详细信息,请参阅CustomToastView