I was trying to change the background color when selecting an item in a RecyclerView but since this is a fairly new feature there isn't any quick and easy answers out there. Selectors didn't work for me either.
List item xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/list_item_bg"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.constraint.ConstraintLayout>
Java code
public class ScheduleTabAdapter extends RecyclerView.Adapter<ScheduleTabAdapter.ScheduleViewHolder> {
public class ScheduleViewHolder extends RecyclerView.ViewHolder {
@Bind(R.id.list_item_bg) ConstraintLayout mCL_BG;
private Context mContext;
//This is used for setting onClick methods for each item
public ScheduleViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
mContext = itemView.getContext();
}
}
build.gradle
annotationProcessor 'com.jakewharton:butterknife:7.0.1'
implementation 'com.jakewharton:butterknife:7.0.1'