我倾向于使用字体片段,并且片段可以控制
为什么以下代码会产生错误?
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rooo = inflater.inflate(R.layout.din2, container, false);
TextView tv1=(TextView) rooo.findViewById(R.id.tv1);
Typeface yaghut=Typeface.createFromAsset(getActivity().getAssets(), "font/BKOODB.ttf");
tv1.setTypeface(yaghut);
return rooo;
}
}
这个错误
最佳答案
onCreateView
仅应返回表示片段的视图。 View上的其他操作应在另一个回调onViewCreated
中执行
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.din2, container, false);
}
@Override
public void onViewCreated (View view, Bundle savedInstanceState) {
TextView tv1=(TextView) view.findViewById(R.id.tv1);
Typeface yaghut=Typeface.createFromAsset(getActivity().getAssets(), "font/BKOODB.ttf");
tv1.setTypeface(yaghut);
}