2

I would like to do the same effect with linearlayout like when you call showDialog. It is easy to disable all components of linear layout, but how can I change the color?

Is it possible to throw some shadow on layout?

Thank you for answer.

vlkpo
  • 199
  • 1
  • 15

3 Answers3

1

Thanks to Asok advice I found this:

Set Alpha/Opacity of Layout

It is working correct for me.

The way how I setClickable to ALL child:

TraverseChildren(GetChildren(_llRest), false);

where

private void TraverseChildren(ArrayList<View> childrenList, boolean b) {
    for (View view : childrenList) {

        view.setClickable(b);
        view.setEnabled(b);

        if (view instanceof ViewGroup)
            TraverseChildren(GetChildren((ViewGroup)view), b);
    }   
}

private ArrayList<View> GetChildren(ViewGroup view) {
    ArrayList<View> children = new ArrayList<View>();
        for (int i = 0; i < view.getChildCount(); i++) 
            if (view.getChildAt(i) != null)
                children.add(view.getChildAt(i));
    return children;
}
Community
  • 1
  • 1
vlkpo
  • 199
  • 1
  • 15
0

I don't think I understood well what you want to do. If you just want to change the color of the layout you can do it in the XML declaration using the android:background attribute or programmatically using the method setBackground or setBackgroundResource on your layout object. If you want to make the activity that you are going to display look somewhat like a dialog (with a translucent background and such) the easiest way is to leave everything on that layout like you would normally do and apply a theme to the activity on the manifest:

<activity android:theme="@android:style/Theme.Dialog">
ZhDev
  • 244
  • 1
  • 7
  • Sorry for insufficient description. On menu button click I want to show my own menu from top of screen. All rest of screen (one linearLayout) I want to change to little darker color and disable. – vlkpo Oct 25 '12 at 08:08
0

You can setAlpha to the parent to apply a transparency to all of the Views children.

Here is an example of the approach I took when I created a View to overlay my primary layout:

RelativeLayout mainRelativeLayout = (RelativeLayout)findViewById(R.id.mainlayout);
mainRelativeLayout.setAlpha((float).45);

My mainRelativeLayout, in this case, contains many ImageViews and TextViews which all inherited the transparency. Which gave me the effect of having a shadow.


setAlpaha of the View class is only supported for API 11+ or Platform Version / Android OS Ver 3.0+

jnthnjns
  • 8,962
  • 4
  • 42
  • 65
  • 1
    This is what what I am looking for, but a setAlpha method has API 3.0, (guess most of us are still targeting 2.x). Set up this field for each child of my linearLayout sound complicate. And it would be needed to set it for background,textColor,hintColor....? – vlkpo Oct 25 '12 at 08:20
  • I found solution with AlphaAnimation. Thank you very much! – vlkpo Oct 25 '12 at 08:32
  • @vlkpo +1 Good point and good find, and just to clarify for future visitors `setAlpaha` of the `View` class is API 11+ or Platform Version / Android OS Ver 3.0+ – jnthnjns Oct 25 '12 at 12:37