我有一個加載RecyclerView的片段,但我想向其中一個RecyclerView的項目中的TextView添加自定義字體。我應該在哪裏設置字體?另外我該如何設置字體?在RecyclerView適配器中設置自定義字體
我不能使用此代碼,
Typeface font = Typeface.createFromAsset((getAssets(),
"myfont.ttf");
,因爲我的活動我不是。那麼我應該如何獲取字體?
這是我的適配器,
public class DiscoverRecyclerAdapter
extends RecyclerView.Adapter<DiscoverRecyclerAdapter.ViewHolder> {
private String[] mDataset;
public static class ViewHolder extends RecyclerView.ViewHolder {
public TextView mText;
public ViewHolder(android.support.v7.widget.CardView v) {
super(v);
mText = (TextView) v.findViewById(R.id.text);
}
}
public DiscoverRecyclerAdapter(String[] myDataset) {
mDataset = myDataset;
}
@Override
public DiscoverRecyclerAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
int viewType) {
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_discover, parent, false);
ViewHolder vh = new ViewHolder((android.support.v7.widget.CardView)v);
return vh;
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.mText.setText(mDataset[position]);
}
@Override
public int getItemCount() {
return mDataset.length;
}
}
適配器內我應該在哪裏設置字體和我將如何設置字體?