A Layout has the following structure:
<LinearLayout
android:id="@+id/card_pack_clickable_area"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/card_pack_bg_selector">
<FrameLayout
android:id="@+id/card_pack_body_frame_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/bg_card_pack_body">
<...>
</FrameLayout>
<TextView
android:id="@+id/card_pack_percentage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@color/bg_card_pack_body"/>
</LinearLayout>
Content of @drawable/card_pack_bg_selector"
:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<solid android:color="#536dfe" />
</shape>
</item>
<item android:state_focused="true">
<shape>
<solid android:color="#536dfe" />
</shape>
</item>
<item android:drawable="@android:color/transparent"/>
</selector>
Problem statement
So the LinearLayout card_pack_clickable_area
has two elements: a FrameLayout card_pack_body_frame_layout
and a TextView card_pack_percentage
.
What I'm trying to achieve is to have the FrameLayout and the TextView as a single clickable area, that's why I've wrapped them into outer LinearLayout.
In Java code I put onClickListener on this LinearLayout. Actually I'm obtaining onClick event when I click either on the FrameLayout or on TextView.
The problem is that the LinearLayout does not change its state as it should do following its background (@drawable/card_pack_bg_selector"
).
The question
How can I have the FrameLayout and the TextView as the united clickable area with the single background, which changes its state pressed/unpressed?