In Android RecyclerView How to change the color of Alternate rows

前端 未结 6 2150
南笙
南笙 2021-02-05 11:45

I am new in android , recently I have learned recyclerview and i want to change the color of rows.

Example: I have 10 rows and I want to change color like

6条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-05 12:09

    Here is a solution :

    LinearLayout ll_search =(LinearLayout)convertView.findViewById(R.id.ll_search);
    
    if(position %2 == 1) {
      ll_search.setBackgroundColor(Color.parseColor("#FFFFFF")); 
    } else { 
      ll_search.setBackgroundColor(Color.parseColor("#d3d3d3")); 
    }
    

提交回复
热议问题