Android 如何使子视图获得;onpress";来自根视图的事件?

Android 如何使子视图获得;onpress";来自根视图的事件?,android,Android,我已经习惯了listview的项处理onpress事件(一些操作使其处于按下和未按下状态)没有任何问题(即使布局复杂)。但现在,我希望LinearLayout也有同样的功能——如果在布局上按任意键,所有子体都应该得到onpress事件 这是我的片段布局的一部分,应该在Press事件中突出显示 <LinearLayout android:id="@+id/ll_about_fragment_feedback" android:gravity="

我已经习惯了listview的项处理onpress事件(一些操作使其处于按下和未按下状态)没有任何问题(即使布局复杂)。但现在,我希望LinearLayout也有同样的功能——如果在布局上按任意键,所有子体都应该得到onpress事件

这是我的片段布局的一部分,应该在Press事件中突出显示

<LinearLayout
            android:id="@+id/ll_about_fragment_feedback"
            android:gravity="center_vertical"
            android:layout_height="54dp"
            android:background="@drawable/about_item_bkg"
            android:layout_width="match_parent">

        <ImageView
                android:layout_height="wrap_content"
                android:background="@drawable/about_item_feedback_icon"
                android:layout_width="wrap_content"
                android:layout_marginLeft="11dp"/>

        <TextView
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="@string/about_fragment_feedback"
                android:layout_marginLeft="14dp"
                android:textSize="16dp"
                android:textColor="@drawable/about_item_textcolor"/>

</LinearLayout>

根布局的背景在按时会更改,但子体的textcolor不会更改。看起来他们没有从根目录获取事件

那么,你能帮忙吗


更新:LinearLayout ll_about_fragment_反馈绑定了OnClickListener,Selecors一切正常只要将
OnClickListener
绑定到布局的根对象(
ll_about_fragment_反馈
)就是这样。

如果您希望
选择器
应用于
线性布局下的所有视图
,则只需将
android:duplicateParentState=“true”
添加到所有子视图中即可

<LinearLayout
    android:id="@+id/ll_about_fragment_feedback"
    android:layout_width="match_parent"
    android:layout_height="54dp"
    android:background="@drawable/about_item_bkg"
    android:gravity="center_vertical" >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="11dp"
        android:background="@drawable/about_item_feedback_icon"
        android:duplicateParentState="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="14dp"
        android:duplicateParentState="true"
        android:text="@string/about_fragment_feedback"
        android:textColor="@drawable/about_item_textcolor"
        android:textSize="16dp" />

</LinearLayout>


为什么不在容器上设置一个
onClickListener
,在您的情况下,
LinearLayout
我知道没有onpress事件。我是说让它受压的东西。不click@bluebyte你是说你在找一个
选择器
?有点像,若你们问的是点击的视觉反馈,那个么听者和它毫无共同之处。正如Asok所述,您需要使用正确的选择器。@WebnetMobile.com在这种情况下,只有根布局处于按下状态,子代-no@bluebyte如果设置了
选择器
,则将
android:duplicateParentState=“true”
添加到
线性布局中的所有子视图中。我想那就行了。