【发布时间】:2018-01-20 21:19:01
【问题描述】:
Typeface hero = Typeface.createFromAsset(getContext().getAssets(),"fonts/Hero Light.otf");
for (int i = 0; i < tabLayout.getTabCount(); i++) {
//noinspection ConstantConditions
TextView tv=
(TextView)LayoutInflater.from(this).inflate(R.layout.item_tab,null);
tv.setTypeface(hero);
tabLayout.getTabAt(i).setCustomView(tv);
}
我在“this”处收到错误,提示类型不兼容。 Mainfragment 无法转换为上下文。 请帮忙,因为这是我在 Tablayout 上更改字体的唯一可行方法。
【问题讨论】:
-
如果此代码在片段中,则使用
getActivity()而不是此 -
题名和正文题不一样。请不要,Fragment 不是内部类,stackoverflow.com/questions/22190797/…