我正在使用片段而且我无法使用这些资产来更改我的信件。我正在使用appcompat的滑动页面。这是我的代码:
public class AcercaFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.acerca, container, false);
TextView logouno = (TextView) getView().findViewById(R.id.logouno);
Typeface typeface = Typeface.createFromAsset(getActivity()
.getAssets(), "fonts/Roboto-Thin.ttf");
logouno.setTypeface(typeface);
return view;
}
}
答案 0 :(得分:0)
尝试这个小小的改变:
public class AcercaFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.acerca, container, false);
TextView logouno = (TextView) view.findViewById(R.id.logouno);
Typeface typeface = Typeface.createFromAsset(getActivity()
.getAssets(), "fonts/Roboto-Thin.ttf");
logouno.setTypeface(typeface);
return view;
}
}
您应用字体的方式还可以,但您必须从视图view
获取TextView。
答案 1 :(得分:0)
您无法在getView()
方法中访问onCreateView
的观看次数。在这里,您应该只返回一个膨胀的视图:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
return inflater.inflate(R.layout.acerca, container, false);
}
然后,初始化UI元素,如下所示:
@Override
public void onActivityCreated(Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
TextView logouno =(TextView) getView().findViewById(R.id.logouno);
Typeface typeface = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Roboto-Thin.ttf");
logouno.setTypeface(typeface);
}