单击任何子视图时,父视图的选择器不起作用

Sha*_*zal 2 android android-layout

选择器的 XML 是:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/primary_light_transparent" android:state_enabled="true" android:state_pressed="true"/>
    <item android:drawable="@color/primary_light_transparent" android:state_enabled="true" android:state_focused="true"/>
    <item android:drawable="@color/primary_light_transparent" android:state_enabled="true" android:state_selected="true"/>
    <item android:drawable="@color/primary_light_transparent" android:state_activated="true" android:state_enabled="true"/>
    <item android:drawable="@drawable/normal"/>
</selector>
Run Code Online (Sandbox Code Playgroud)

布局 XML 是:

<FrameLayout
android:id="@+id/keypad_6"
     android:layout_width="0dp"
     android:layout_height="match_parent"
     android:layout_weight="1"
     android:background="@drawable/button_selector"
     android:descendantFocusability="beforeDescendants"
     android:onClick="onClick" >

     <Button
     android:id="@+id/keypad_6_bt"
     style="@style/Button.Keypad.Numeric"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:onClick="onClick"
     android:text="6" />

    <TextView
     android:id="@+id/keypad_6_tv"
     style="@style/Keypad_Letters"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:layout_gravity="bottom"
     android:gravity="center_horizontal"
     android:onClick="onClick"
     android:text="MNO"
     android:textColor="@color/keypad_digits_color" />
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

我正在寻找的是,当FrameLayout将单击 FrameLayout的子视图(Button 或 TextView)时,FrameLayout 的选择器应该可以工作并且应该突出显示整个布局。

我无法实现这一目标,并期待知道我该如何做到这一点

Arc*_*pgc 5

添加 android:addStatesFromChildren="true" 到您的FrameLayout