我为适配器设置了listview布局。我想为这个特定的适配器设置自定义字体,我该怎么办。我可以使用两行以下吗?
Typeface customfont = Typeface.createFromAsset(this.getAssets(), "fonts/omnesreg.ttf");
textview.setTypeface(customfont);
答案 0 :(得分:1)
持有人可以帮助您
创建自己的自定义适配器并为文本设置字体。
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// ViewHolder will buffer the assess to the individual fields of the row
// layout
ViewHolder holder;
// Recycle existing view if passed as parameter
// This will save memory and time on Android
// This only works if the base layout for all classes are the same
View rowView = convertView;
if (rowView == null) {
LayoutInflater inflater = context.getLayoutInflater();
rowView = inflater.inflate(R.layout.main_listview, null, true);
holder = new ViewHolder();
holder.textView = (TextView) rowView.findViewById(R.id.main_name);
rowView.setTag(holder);
} else {
holder = (ViewHolder) rowView.getTag();
}
Typeface customfont = Typeface.createFromAsset(this.getAssets(), "fonts/omnesreg.ttf");
holder.textView.setTypeface(customfont);
holder.textView.setText(title);
return rowView;
}