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 上的字体的唯一有效方法。
最佳答案
如果您的代码位于 Fragment 中,则使用 getActivity(),因为在这里这不适用于内部类。
关于java - fragment 中的 LayoutInflater 错误 "incompatible types",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45650732/