How do I grey out a view uniformly which contains many different items - ImageViews, TextViews, background image. Do I have to grey out each thing individually? Or is there
It depends entirely on the method you are using to "gray out" items. If you are doing so by calling setEnabled(false)
on the parent ViewGroup
, by default state flags (like disabled) do not trickle down to the child views. However, there are two simple ways you can customize this:
One option is to add the attribute android:duplicateParentState="true"
to each child view in your XML. This will tell the children to get their state flags from the parent. This will mirror ALL flags however, including pressed, checked, etc...not just enabled.
Another option is to create a custom subclass of your ViewGroup
and override setEnabled()
to call all the child views as well, i.e.
@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
for(int i=0; i < getChildCount(); i++) {
getChildAt(i).setEnabled(enabled);
}
}