6

So what I'm trying to do is create a translucent and blurry background to a linear layout.

Right now I have a linear layout thats completely black covering up some information that a key must be purchased to show, however I would like it to be blurred out, not completely covered as it ruins the layout, it needs to stay there, just blurry and illegible.

Thanks for your help!

Samuel
  • 4,337
  • 3
  • 29
  • 35

3 Answers3

2

I'm not sure for Linearlayout. But for your activity you can try this.

getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND, WindowManager.LayoutParams.FLAG_BLUR_BEHIND);

and use the setContentView(R.layout.your_layout); method

san
  • 1,845
  • 13
  • 23
  • 1
    yes, that works for the window, however on the layout itself it does not, for more clarification its two side by side linear layouts ( in landscape ) and the right one needs to be blurred, but still there, and the background is not solid so it cannot just be covered, because I still want to show whats there but be illegible – Samuel Jan 25 '12 at 02:39
  • I could find no way to apply for a linear layout. But I've an idea. You can use the window for translucent background. And where ever u want background you can apply background. And dont apply background for the ones you don't want. For eg in your case u can apply background for one of your linear layouts in the left and dont apply any background for the other linear layout. I think this could work. Not the proper way though. – san Jan 25 '12 at 02:57
  • the window does however, have a background which is a non-solid image – Samuel Jan 25 '12 at 03:00
  • So your window already has a background. Your linear layout lies on top of the window. In that case even if u make ur linear layout translucent you wud end up in showing ur current window and not the previous window. It doesn't make sense to me. – san Jan 25 '12 at 03:37
  • It shows the window, and the window is translucent, showing what is below it, correct? so now, I would like to make everything it is showing (underneath) blurry, so I need to make the one layer blur, or basically anything to make the view blur will work, it can be the other layers if possible – Samuel Jan 25 '12 at 03:43
0

If you want to make any View Background translucent then use below code

 android:background="@null" 

it work me for EditText. And AFAIK it should work for any view.So once try for this one

Tofeeq Ahmad
  • 11,935
  • 4
  • 61
  • 87
0

How about trying GLSurfaceView:

http://developer.android.com/resources/articles/glsurfaceview.html

Within Android SDK there is an example on getting translucent surface (app/TranslucentActivity.java), essentially setting the alpha channel:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Create our Preview view and set it as the content of our
    // Activity
    mGLSurfaceView = new GLSurfaceView(this);
    // We want an 8888 pixel format because that's required for
    // a translucent window.
    // And we want a depth buffer.
    mGLSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
    // Tell the cube renderer that we want to render a translucent version
    // of the cube:
    mGLSurfaceView.setRenderer(new CubeRenderer(true));
    // Use a surface format with an Alpha channel:
    mGLSurfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
    setContentView(mGLSurfaceView);
}

For other threads on using Alpha channel refer to:

Alpha Channel Blur

How can I blur and dim an image to be used as an activity background?

blur a image at android

Another example is the app/TranslucentBlurActivity.java (from Android SDK):

public class TranslucentBlurActivity extends Activity {
    /**
     * Initialization of the Activity after it is first created.  Must at least
     * call {@link android.app.Activity#setContentView setContentView()} to
     * describe what is to be displayed in the screen.
     */
    @Override
    protected void onCreate(Bundle icicle) {
        // Be sure to call the super class.
        super.onCreate(icicle);

        // Have the system blur any windows behind this one.
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
                WindowManager.LayoutParams.FLAG_BLUR_BEHIND);

        // See assets/res/any/layout/translucent_background.xml for this
        // view layout definition, which is being set here as
        // the content of our screen.
        setContentView(R.layout.translucent_background);
    }
}
Community
  • 1
  • 1
Peter Teoh
  • 6,337
  • 4
  • 42
  • 58