Recyclerview row item selection color change

后端 未结 3 1485
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-17 19:22

I am able to change the color of the text and background of imageview of the row clicked of my recyclerview in my navigation dra

3条回答
  •  太阳男子
    2021-01-17 19:44

    Change the onBindViewHolder method of your NavigationDrawerAdapter.java into this:

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        if(position == selected_item) {
            holder.title.setTextColor(Color.parseColor("#00aaff"));
            holder.imgViewIcon.setBackgroundResource(R.drawable.ic_circle);
        } else {
            holder.title.setTextColor(Color.parseColor("#00000")); //actually you should set to the normal text color
            holder.imgViewIcon.setBackgroundResource(0);
        }
        NavDrawerItem current = data.get(position);
        holder.title.setText(current.getTitle());
        holder.imgViewIcon.setImageResource(current.getIcon());
    
    
    }
    

提交回复
热议问题