我想在导航抽屉中设置一个自定义字体,已经搜索过问题但没有找到任何解决方案......这是我想要设置自定义字体的NavigationDrawerAdapter.java:
我也尝试过NavigationDrawerFragment.java和我的MainActivity.java,但这也没用。因为我可以在所有其他适配器中设置自定义字体,我也尝试在那里进行,但它不起作用...
public class NavigationDrawerAdapter extends ArrayAdapter {
private Object[] array;
private int resource;
private int textViewResourceId;
Activity a;
private Activity activity;
public NavigationDrawerAdapter(Context context, int resource, int textViewResourceId, Object[] objects) {
super(context, resource, textViewResourceId, objects);
this.array = objects;
this.resource = resource;
this.textViewResourceId = textViewResourceId;
this.activity = activity;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(resource, null);
}
TextView row = (TextView) v.findViewById(textViewResourceId);
row.setText((String) array[position]);
TextView navtext = (TextView) v.findViewById(R.id.navigation_drawer_text);
Typeface tf = TypefaceUtil.getAndCache(activity, "Lato-Semibold.ttf");
navtext.setTypeface(tf);
switch (position) {
case 0:
row.setCompoundDrawablesWithIntrinsicBounds(R.drawable.btn_material_charts, 0, 0, 0);
break;
case 1:
row.setCompoundDrawablesWithIntrinsicBounds(R.drawable.btn_material_search, 0, 0, 0);
break;
case 2:
row.setCompoundDrawablesWithIntrinsicBounds(R.drawable.btn_material_my_music, 0, 0, 0);
break;
case 3:
row.setCompoundDrawablesWithIntrinsicBounds(R.drawable.btn_material_radio, 0, 0, 0);
break;
case 4:
row.setCompoundDrawablesWithIntrinsicBounds(R.drawable.btn_material_play, 0, 0, 0);
break;
case 5:
row.setCompoundDrawablesWithIntrinsicBounds(R.drawable.btn_material_listening_local, 0, 0, 0);
break;
case 6:
row.setCompoundDrawablesWithIntrinsicBounds(R.drawable.btn_material_news, 0, 0, 0);
break;
case 7:
row.setCompoundDrawablesWithIntrinsicBounds(R.drawable.btn_material_settings, 0, 0, 0);
break;
case 8:
row.setCompoundDrawablesWithIntrinsicBounds(R.drawable.btn_material_about, 0, 0, 0);
break;
}
return row;
}
}