这是我的片段

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()给我一个错误:无法解析方法。我想我需要这里的内容。我在哪里可以得到它?

最佳答案

您需要一个ContextgetActivity()会让您得到一个。

getActivity().getAssets()


但您必须将其移至onActivityCreated(Bundle bundle)

关于java - 从哪里获取内容 fragment ?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29356435/

10-13 03:01