NavigationDrawer 上的自定义字体

Custom font on NavigationDrawer

我正在尝试更改导航抽屉上的字体,我正在使用带有适配器的自定义 xml 文件,因此我可以成功更改 ListView 中每个元素的颜色和背景,但我无法更改字体,AndroidStudio 给我一个 空对象引用 所以,我认为它没有找到文本视图。我的代码:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

    mDrawerListView = (ListView) inflater.inflate(
            R.layout.fragment_navigation_drawer, container, false);
    TextView lbl = (TextView) mDrawerListView.findViewById(R.id.section_label);
    Typeface tf = Typeface.createFromAsset(getActivity().getAssets(),"fonts/Jaapokki-Regular.otf");
    lbl.setTypeface(tf);
    mDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            selectItem(position);
        }
    });
    mDrawerListView.setAdapter(new ArrayAdapter<String>(
            getActionBar().getThemedContext(),
            R.layout.fragment_main,
            R.id.section_label,
            new String[]{
                    getString(R.string.title_section1),
                    getString(R.string.title_section2),
                    getString(R.string.title_section3),
                    "Acerca de...",
            }));

    mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
    return mDrawerListView;
}

非常感谢!

试试这个

mDrawerListView.setAdapter(new ArrayAdapter<String>(getActionBar().getThemedContext(), R.layout.fragment_main,R.id.section_label, new String[]{
                getString(R.string.title_section1),
                getString(R.string.title_section2),
                getString(R.string.title_section3),
                "Acerca de...",
                }) {
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = super.getView(position, convertView, parent);          
        TextView tv=(TextView)v.findViewById(R.id.section_label);
        tv.setTypeface(tf);             
        return v;
    }
});