How can I make a list item have such a blue background when clicked?
Here is code from my fragment when i click on item:
override fun onListItemClick(itemIndex: Int, itemCode: String, itemViewId: Int) {
val connectionGuid = (adapter.getItem(itemIndex) as ConnectionViewModel).guid
proceedView.isEnabled = true
proceedView.setOnClickListener { proceedConnection(connectionGuid) }
}
And here is code of my adapter:
class ConnectionItemHolder(parent: ViewGroup, private val listener: ListItemClickListener?) :
RecyclerView.ViewHolder(parent.inflateListItemView(R.layout.view_item_connection)) {
private val logoImageView = itemView.findViewById<ImageView>(R.id.logoImageView)
private val titleView = itemView.findViewById<TextView>(R.id.titleView)
private val subTitleView = itemView.findViewById<TextView>(R.id.subTitleView)
init {
itemView.setOnClickListener {
if (adapterPosition > RecyclerView.NO_POSITION)
listener?.onListItemClick(itemIndex = adapterPosition)
}
}
fun bind(item: ConnectionViewModel) {
logoImageView.loadRoundedImage(
imageUrl = item.logoUrl,
placeholderId = R.drawable.ic_logo_bank_placeholder,
cornerRadius = itemView.resources.getDimension(R.dimen.dp_12)
)
titleView.text = item.name
subTitleView.text = item.statusDescription
subTitleView.setTextColorResId(item.statusColorResId)
}
}
And here is my layout view_item_connection
:
<androidx.cardview.widget.CardView 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:layout_width="wrap_content"
android:layout_height="@dimen/dp_80"
android:layout_marginStart="@dimen/dp_16"
android:layout_marginEnd="@dimen/dp_16"
android:clipToPadding="false"
android:foreground="?android:attr/selectableItemBackground"
app:cardCornerRadius="@dimen/dp_6"
app:cardElevation="@dimen/dp_20">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/app_logo_background">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginEnd="@dimen/dp_15"
android:layout_toEndOf="@+id/logoImageView"
android:orientation="vertical">
<TextView
android:id="@+id/titleView"
style="@style/Text18Primary"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="bottom"
android:maxLines="1"
tools:text="Demobank" />
<TextView
android:id="@+id/subTitleView"
style="@style/Text14Secondary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_3"
android:maxLines="1"
tools:text="Connected on 12 sept. 2019, 18:02" />
</LinearLayout>
<ImageView
android:id="@+id/logoImageView"
style="@style/ConnectionLogoImage"
android:layout_centerVertical="true"
android:contentDescription="@null" />
</RelativeLayout>
</androidx.cardview.widget.CardView>