选择器的 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>
布局 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>
我正在寻找的是,当单击FrameLayout
的 subview (Button或TextView)时,FrameLayout的选择器应该起作用并且应该突出显示整个布局。
我无法实现这一目标,并期待知道我该如何做到这一点
最佳答案
添加
android:addStatesFromChildren="true"
到你的FrameLayout
关于android - 单击任何 subview 时,父 View 的选择器不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29387229/