我有一个片段加载RecyclerView但我想在其中一个RecyclerView的项目中向TextView添加自定义字体.我的适配器应该在哪里设置字体?我怎么设置字体?
我无法使用此代码,
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; } }
我应该在适配器中设置字体以及如何设置字体?