简体   繁体   English

如何在RecyclerView“ Android应用程序”中设置第一行的背景颜色

[英]How can I set background color of first Row in RecyclerView “Android Application”

I used RecyclerView for displaying items as rows, and all the rows having background color is white. 我使用RecyclerView将项目显示为行,并且所有具有背景颜色的行均为白色。 But i want to change first row background color as silver and rest will be white. 但我想更改第一行的背景色,如银色,其余将为白色。 Please help me. 请帮我。

In the onBindViewHolder 在onBindViewHolder中

if( position == 0){
   holder.view.setBackgroundColor(whatever_color);
}

In viewHolder class 在viewHolder类

View view;
public MyViewHolder(View itemView){
  view = itemView;

In your onBindViewHolder method of recycleView adapter class, you can use position parameter to perform required functionality. 在recycleView适配器类的onBindViewHolder方法中,可以使用position参数执行所需的功能。 In your case, it will be position = 0 在您的情况下,它将是position = 0

@Override
public void onBindViewHolder(ViewHolder holder, final int position) {

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM