gpt4 book ai didi

java - fragment 中的 LayoutInflater 错误 "incompatible types"

转载 作者:行者123 更新时间:2023-12-01 20:16:47 25 4
gpt4 key购买 nike

enter image description here

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com