EDIT - example below refers for Android pre-SDK11, but I just found out about an amazingly great library called Nine Old Androids, The amazing thing it does is enabling all animation capabilities of Android 3.0 for all API versions!!!
Previous answer
I actually encountered this kind of problem when wanted to set alpha dynamically on a complex layout.
I created an override of onSetAlpha()
and added another recursive function that checks every kind of view for background image, drawables and text colors.
@Override
public boolean onSetAlpha(int alpha)
{
return onSetAlpha(alpha, theLayoutYouWantToSetAlphaTo);
}
public boolean onSetAlpha(int alpha, View view)
{
if (view instanceof ViewGroup)
{
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++)
{
onSetAlpha(alpha, ((ViewGroup) view).getChildAt(i));
if (((ViewGroup) view).getBackground() != null) ((ViewGroup) view).getBackground().setAlpha(alpha);
}
}
else if (view instanceof ImageView)
{
if (((ImageView) view).getDrawable() != null) ((ImageView) view).getDrawable().setAlpha(alpha);
if (((ImageView) view).getBackground() != null) ((ImageView) view).getBackground().setAlpha(alpha);
}
else if (view instanceof TextView)
{
((TextView) view).setTextColor(((TextView) view).getTextColors().withAlpha(alpha));
if (((TextView) view).getBackground() != null) ((TextView) view).getBackground().setAlpha(alpha);
}
else if (view instanceof EditText)
{
((EditText) view).setTextColor(((EditText) view).getTextColors().withAlpha(alpha));
if (((EditText) view).getBackground() != null) ((EditText) view).getBackground().setAlpha(alpha);
}
return true;
}
You can add other kinds of views as you need.