下面的代码不起作用,有什么更改文字颜色的正确方法吗?
public class Adapter extends RecyclerView.Adapter<Adapter.ViewHolder> {
private List<TodayGmodel> model;
private Context context;
public Adapter(Context context, List<TodayGmodel> model) {
this.model = model;
this.context = context;
}
@Override
public Adapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.timer_adapter_layout, viewGroup, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(final Adapter.ViewHolder viewHolder, int position) {
TodayGmodel todayGmodel = model.get(position);
viewHolder.refreshTime(todayGmodel.getCalculateEnd());
Log.e("timerLogList", "" + model.get(position).getCalculateEnd());
}
@Override
public void onViewAttachedToWindow(@NonNull ViewHolder holder) {
int pos = holder.getAdapterPosition();
TodayGmodel todayGmodel = model.get(pos);
holder.refreshTime(todayGmodel.getCalculateEnd());
}
@Override
public void onViewDetachedFromWindow(@NonNull ViewHolder holder) {
if (holder.getDownTimer() != null)
holder.getDownTimer().cancel();
}
@Override
public int getItemCount() {
return model.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
public TextView tv_timer;
private CountDownTimer downTimer;
private long remainTime = 0;
public ViewHolder(View view) {
super(view);
tv_timer = view.findViewById(R.id.tv_timer);
}
public void refreshTime(long timer) {
if (timer > 0) {
downTimer = new CountDownTimer(timer * 1000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
remainTime = millisUntilFinished / 1000;
int seconds = (int) (millisUntilFinished / 1000);
int hours = seconds / (60 * 60);
int tempMint = (seconds - (hours * 60 * 60));
int minutes = tempMint / 60;
seconds = tempMint - (minutes * 60);
tv_timer.setText(String.format("%02d", hours)
+ ":" + String.format("%02d", minutes)
+ ":" + String.format("%02d", seconds));
if (remainTime > 50) {
tv_timer.setBackgroundColor(ContextCompat.getColor(context, R.color.color1));
} else if (remainTime < 50 && remainTime > 20){
tv_timer.setBackgroundColor(ContextCompat.getColor(context, R.color.color2));
} else {
tv_timer.setBackgroundColor(ContextCompat.getColor(context, R.color.color4));
}
}
@Override
public void onFinish() {
}
}.start();
} else {
tv_timer.setText("Finish");
if (downTimer != null)
downTimer.cancel();
}
}
public CountDownTimer getDownTimer() {
return downTimer;
}
}
}
答案 0 :(得分:0)
<xsl:text color="green">Sold</xsl:text>
xslt中没有像color这样的属性。您必须在要为文本着色的位置提供格式和输入。