2017-06-14 33 views

回答

1

你可以在你的適配器聲明一個新的布爾變量,讓我們把它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)); 
}