I have a LinearLayout with some other LinearLayouts inside. The children layouts have a background selector set. I need to change the color of the parent layout as well when a children is pressed. I have set a background selector as well for the parent, but it only triggers when clicking outside of any children.
How can I avoid this?
Thanks!
Try adding this to the layout attributes for the parent LinearLayout:
android:addStatesFromChildren="true"
Alternatively, in code call:
parentLayout.setAddStatesFromChildren(true);
In either case, be sure that the child layouts do not have the android:duplicateParentState
attribute set (and do not call setDuplicateParentState(true)
), or you will get an exception at run time when the system detects the circular dependency.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With