I am testing creating a compound view, so I started with a Linear Layout containing a ImageView and a TextView. These LinearLayout will represent a view similar to a partial list, and I made it clickable. The inner Views of the layout have selectors as its color (TextView) and image (ImageView). In the API 19 (KitKat), the click behavior is ok (screenshot 1) but on API 15 and API 10 (screenshot 2), the click didn't changed the selector state.
The code of each 'list item' is:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/listitem_login"
android:clickable="true"
android:gravity="center"
android:orientation="horizontal"
android:padding="15dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:src="@drawable/signin_signup_icon_facebook" />
<TextView
style="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Facebook"
android:textColor="@color/option_text_color" />
</LinearLayout>
EDIT: I used the touch listener approach. If someday I find a best solution (without Java code), I edit here. My approach, based on the answers (adding the a View.OnTouchListener to the LinearLayouts):
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
ViewGroup container = (ViewGroup) view;
boolean pressed;
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) pressed = true;
else if (motionEvent.getAction() == MotionEvent.ACTION_UP) pressed = false;
else return false;
for (int i = 0; i < container.getChildCount(); i++) {
container.getChildAt(i).setPressed(pressed);
}
return false;
}
In an old 2.3 Android the code runs a bit slowly but works too.