In this application, I noticed that if you click on an element and hold it, the element is painted in a grayish color, making it clear to the user that he clicked on it. As in ListView. How to do also? And then I press / hold on the element, but somehow it is not clear. In ListView, too, was painted in a grayish color.

enter image description here

Markup

<?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="10dp"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:orientation="vertical" android:padding="10dp"> <de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/imgRadio" android:layout_width="60dp" android:layout_height="60dp" android:src="@mipmap/ic_launcher" app:civ_border_color="@android:color/white" app:civ_border_width="2dp" /> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:background="?android:selectableItemBackground" android:gravity="center_vertical" android:orientation="vertical" android:paddingLeft="8dp" android:paddingRight="8dp"> <TextView android:id="@+id/txtRadioTitle" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center_vertical" android:singleLine="true" android:text="Название радио" android:textColor="@android:color/darker_gray" android:textSize="16sp" /> <TextView android:id="@+id/txtRadioCity" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center_vertical" android:singleLine="true" android:text="Город" android:textColor="@android:color/darker_gray" android:textSize="16sp" /> </LinearLayout> <ImageButton android:id="@+id/btnFavorite" android:layout_width="60dp" android:layout_height="60dp" android:background="@drawable/favorites_button" android:focusable="false" android:onClick="onFavoriteClick" android:padding="15dp" android:scaleType="centerCrop" app:srcCompat="@drawable/ic_star_black" /> </LinearLayout> </android.support.v7.widget.CardView> 
  • 3
    Why do you delete your questions? I spent the time writing the answer, but I could not send it - the question was deleted. Stop doing that. We are not answering questions for specific users, but compiling a publicly available knowledge base. Your questions belong to the community, not to you personally. - Yuriy SPb

2 answers 2

LinearLayout in which you have view elements set the background:

 android:background="?android:selectableItemBackground" 

 <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/cardView" android:layout_width="match_parent" android:layout_height="wrap_content" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:background="?android:selectableItemBackground" > 
  • I did this, but by clicking on the item on the list it is not noticeable that the background somehow changes - Scorpion
  • Show the markup code, I just write the application, also implemented, it works great for me. - McDaggen
  • In question added - Scorpion
  • It worked. It turns out that LinerLayout added the attribute - Scorpion

If you have your own adapter for ListView, then handler will tell it via setOnItemLongClickListener, within which you can tint, animate or something else to do with your views.