我有一个回收站视图,想更改 textview 文本某些部分的颜色。
这是我的代码:
public class MyAdapter extends RecyclerView.Adapter<MyEarningsAdapter.ViewHolder> {
public ArrayList<WageItemDataSet> wageItemList;
private Context context;
private Spannable spanText;
private ForegroundColorSpan fcs;
private RelativeSizeSpan rss;
public MyAdapter(Context context) {
wageItemList = new ArrayList<>();
this.context = context;
fcs = new ForegroundColorSpan(Color.BLACK);
rss = new RelativeSizeSpan(0.8f);
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_wage_list, parent, false));
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
WageItemDataSet item = wageItemList.get(position);
spanText = new SpannableString("Fare: "+item.totalFare);
spanText.setSpan(fcs, 0, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spanText.setSpan(rss, 0, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
holder.tvFareAmount.setText(spanText);
}
public class ViewHolder extends RecyclerView.ViewHolder {
TextView tvFareAmount;
public ViewHolder(View itemView) {
super(itemView);
tvFareAmount = (TextView) itemView.findViewById(R.id.tvFareAmount);
tvFareAmount.setTypeface(openSansRegular);
}
}
}
它不会改变颜色或文本大小。我究竟做错了什么??