这是我的 fragment
public class Top_Tab1 extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v =inflater.inflate(R.layout.top_tab_1,container,false);
Typeface type_thin = Typeface.createFromAsset(getAssets(),"fonts/Roboto-Thin.ttf");
return v;
}
getAssets() 给我一个错误:无法解析方法。我想我需要这里的内容。我在哪里可以获得它?
最佳答案
您需要一个Context
,getActivity()
将为您提供一个。
getActivity().getAssets()
但您必须将其移至onActivityCreated(Bundle bundle)
。
关于java - 从哪里获取 fragment 中的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29356435/