你可以在你的適配器聲明一個新的布爾變量,讓我們把它changeColor
其初始化爲false
在適配器構造函數,然後在你的onClick
操作方法將其設置爲true
並調用yourAdapter.notifyDataSetChanged()
。最後,將測試添加到適配器的onBindViewHolder
方法中,如下所示:
// your onclick method
void onClick() {
//code..;
changeColor = true;
yourAdapter.notifyDataSetChanged();
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
if(changeColor)
holder.yourItemTitle.setTextColor(ContextCompat.getColor(context, newTitleColor));
else
holder.yourItemTitle.setTextColor(ContextCompat.getColor(context, defaultTitleColor));
}