亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何更改卡片視圖的背景顏色?

如何更改卡片視圖的背景顏色?

喵喔喔 2022-12-15 10:48:20
Cardview一旦它被點擊,我試圖改變它的背景顏色。這里列出通知歷史記錄RecyclerView。Cardview顏色只在那個時候改變。如果我返回并再次打開應用程序意味著它不會被更改。我必須做什么?這是我的適配器類public class NotificationsAdapter extends RecyclerView.Adapter<NotificationsAdapter.ViewHolder> {    public static final String TAG = "DataViewHolder";    private Context context;    private ArrayList<NotificationsModel> notificationsModelList;    public NotificationsAdapter(Context context, ArrayList<NotificationsModel> notificationsModelList) {        this.context = context;        this.notificationsModelList = notificationsModelList;    }    @Override    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {        View v = LayoutInflater.from(parent.getContext())                .inflate(R.layout.notification_layout, parent, false);        Log.d(TAG, "onCreateViewHolder: ");        return new ViewHolder(v);    }    @Override    public void onBindViewHolder(ViewHolder holder, int position) {        final NotificationsModel notificationsModel = notificationsModelList.get(position);        holder.title_news.setText(notificationsModel.getTitle());        holder.notif_message.setText(notificationsModel.getMessage());    }    @Override    public int getItemCount() {        return notificationsModelList == null ? 0 : notificationsModelList.size();    }    public class ViewHolder extends RecyclerView.ViewHolder {        TextView notif_message, title_news;        //Initializing Views        public ViewHolder(View itemView) {            super(itemView);            title_news = (TextView) itemView.findViewById(R.id.title_news);            notif_message = (TextView) itemView.findViewById(R.id.notif_message);            CardView cardView = (CardView) itemView.findViewById(R.id.cardViewLayoutNotif);            itemView.findViewById(R.id.notif_message);            itemView.setOnClickListener(new View.OnClickListener() {                }            });        }    }}
查看完整描述

1 回答

?
慕少森

TA貢獻2019條經驗 獲得超9個贊

IsColorChanged您可以在您的內部添加標志,notificationsModel并且每當您更改cardview模型中更新標志的顏色時,


在您的onBindViewHolder中,您可以添加如下檢查:


if(IsColorChanged){

    cardView.setCardBackgroundColor(Color.WHITE);

}else{

    cardView.setCardBackgroundColor(Color.BLACK);// ANY OTHER COLOR

}


查看完整回答
反對 回復 2022-12-15
  • 1 回答
  • 0 關注
  • 173 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號