问题
I'm creating an app with listview and I added few values like 101,102 to 110 to the listview. Now I have to change the listview item background colour using edittext. For example if I type 101 and click submit button, background colour of 101 should change. Please help. Please......
回答1:
First Declare the layout of adapter
linearlayout = itemView.findViewById(R.id.linearLayout);
then set color if match the number in onBindViewHolder()
if((position.Value())==typedValue){
holder.linearlayout.setBackgroundColor(Color.parseColor("#FF003B"));
}
回答2:
You can try
listView.setSelectorColor(getResources().getColor(R.color.colorPrimaryDark))
You can see this [Change background color of selected item on a ListView
来源:https://stackoverflow.com/questions/59307997/how-to-change-listview-item-background-color-using-if-condition-android