Dim / Blur / Blur activity when opening navigation drawer

I am using LDrawer in my project. I need to make the action that hosts the navigation drawer fade / darken / blur when the navigation drawer is opened.

I came across similar questions on Stackoverflow and I couldn't find a satisfying answer.

Is there any simple trick to make the activity layout dark / dim / blurry when I open mine NavigationDrawer

I have RelativeLayout

my activity defined as

RelativeLayout myActivity = (RelativeLayout) findViewById(R.id.myActivity)

      

I have switch code for NavigationDrawer

below

public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            if (mDrawerLayout.isDrawerOpen(mDrawerList)) {
                mDrawerLayout.closeDrawer(mDrawerList);
            } else {
               //I want to manipulate myActivity Layout here
                mDrawerLayout.openDrawer(mDrawerList);
            }
        }
        return super.onOptionsItemSelected(item);
    }

      

+3


source to share


1 answer


Is there any simple trick to make the layout of the Darken / Dim / Blur activity when I open my NavigationDrawer?

Yes, you can just change the background image of your activity as a blur when you open the drawer.

Another way is to change the alpha or your activity just with setalpha () and pass in the value of how many changes you want.

If you have a list control in your activity and you want to make this blur, then below code will work.



Display display = getActivity().getWindowManager().getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        int screenWidth = size.x;
        int screenHeight = size.y;

Bitmap blurBitmap = BitmapFactory.decodeResource(getResources(),
                R.drawable.invitation_blur_bg);

        Rect rect = new Rect(0, 0, blurBitmap.getWidth(), blurBitmap.getHeight());

      

Implement an OnScrollListener in your Activity or Fragment where you want to apply this.

@Override
    public void onScroll(AbsListView view, int firstVisibleItem,
            int visibleItemCount, int totalItemCount) {

        for (int i = 0; i < listview.getChildCount(); i++) {
            View c = listview.getChildAt(i);

            Rect r = new Rect(); 
            c.getHitRect(r);

            RelativeLayout llItemBg = ((RelativeLayout ) c.findViewById(R.id.root_layout of list item);

            Drawable d = new BitmapDrawable(getResources(), cropImage(r,c));

            itemBackground.setBackgroundDrawable(d);

        }
    }
    private Bitmap cropImage(Rect r, View c2) {

        Bitmap bmOverlay = Bitmap.createBitmap(screenWidth - 60,
                c2.getHeight(), Bitmap.Config.ARGB_8888);
        Rect rect1=new Rect(0, 0, bmOverlay.getWidth(), bmOverlay.getHeight());
        Paint p = new Paint();
        Canvas c = new Canvas(bmOverlay);
        rect.right = r.right;
        rect.top = rect.top;
        rect.bottom = r.bottom / 2;

        c.drawBitmap(blurBitmap, r, rect1, p);

        return bmOverlay;
    }

      

0


source







All Articles