如何在android中向ListView添加自定义字体
如何在代码中输入字体如何在android中向ListView添加自定义字体,android,android-studio,android-fonts,Android,Android Studio,Android Fonts,如何在代码中输入字体 public class AndalosAdapter extends BaseAdapter { private Activity activity; private ArrayList<HashMap<String, String>> data; private static LayoutInflater inflater=nu
public class AndalosAdapter extends BaseAdapter {
private Activity activity;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater=null;
int imageResource;
public AndalosAdapter(Activity a, ArrayList<HashMap<String, String>> d, int imageResource) {
activity = a;
data=d;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.imageResource = imageResource;
}
public int getCount() {
return data.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.list_row, null);
TextView title = (TextView)vi.findViewById(R.id.title);
TextView duration = (TextView)vi.findViewById(R.id.duration);
ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image); // thumb image
HashMap<String, String> song = new HashMap<String, String>();
song = data.get(position);
title.setText(song.get(AndalosList.KEY_TITLE));
artist.setText(song.get(CustomizedListView.KEY_ARTIST));
duration.setText(song.get(AndalosList.KEY_DURATION));
thumb_image.setImageResource(imageResource);
return vi;
}
}
这是两个主要的文本视图,我想在其中添加自定义字体
将字体放入资源->字体->字体目录中
现在假设您要在TextView中添加字体,请执行以下操作
TextView tv=TextViewfindViewByIdR.id.logo\u text;
Typeface=Typeface.createFromAssetgetAssets,
font/Your Directry/Your font.ttf;
tv.settypeface
就这些
无法以其他方式工作?在目录中添加字体,如下所示
TextView title = (TextView)vi.findViewById(R.id.title);
TextView duration = (TextView)vi.findViewById(R.id.duration);