I want simply highlight item when I press on it.
I have selectors below (@drawable/expandable_menu)
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:exitFadeDuration="@android:integer/config_mediumAnimTime">
<item android:drawable="@color/purple_200" android:state_pressed="true" />
<item android:drawable="@color/purple_500" android:state_selected="true" />
<item android:drawable="@color/chat" android:state_activated="true" />
<item android:drawable="@color/transparent"/>
</selector>
In my onclick listener I select this item
RecyclerView XML:
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="70dp"
android:id="@+id/chat_messages"
app:stackFromEnd="true"
android:clickable="true"
android:focusableInTouchMode="true"
android:background="@drawable/expandable_menu"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:focusable="true">
Message XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="10dp"
android:layout_gravity="left"
>
<TextView
android:id="@+id/chat_msg_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="this is me"
android:textColor="@color/black"
android:textSize="16dp"
android:background="@color/cardview_shadow_start_color"
android:padding="10dp"
android:layout_alignParentTop="true" />
</RelativeLayout>
I followed this answer (https://stackoverflow.com/a/30046476) but no success
question from:
https://stackoverflow.com/questions/65882091/cannot-highlight-items-in-recyclerview-with-selectors 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…