变暗/点心/模糊活动时的导航抽屉被打开 [英] Darken/Dim/Blur Activity when navigation drawer is open

查看:195
本文介绍了变暗/点心/模糊活动时的导航抽屉被打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 LDrawer 在我的项目。我需要它承载导航抽屉打开时,导航抽屉变暗/暗/模糊的活动。

我已经通过#2类似的问题消失了,我还没有找到一个satisfiying答案。

有没有什么简单的一招,使活动的布局变暗/暗/模糊当我睁开 NavigationDrawer

我有 RelativeLayout的定义为

我的活动

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

我有以下

切换code为 NavigationDrawer

 公共布尔onOptionsItemSelected(菜单项项){
        如果(item.getItemId()== android.R.id.home){
            如果(mDrawerLayout.isDrawerOpen(mDrawerList)){
                mDrawerLayout.closeDrawer(mDrawerList);
            }其他{
               //我想在这里操纵myActivity布局
                mDrawerLayout.openDrawer(mDrawerList);
            }
        }
        返回super.onOptionsItemSelected(项目);
    }


解决方案

有没有什么简单的一招,使活动的布局变暗/点心/模糊当我睁开NavigationDrawer?

是的,你可以简单地改变,因为你的模糊活动的背景图像当您打开抽屉。

另一种方法是改变字母或setalpha(您的活动简单),并通过该值多少变化想要的。

如果你有你的活动列表控制和你想的那么模糊低于code会工作。

 显示显示= getActivity()getWindowManager()getDefaultDisplay()。
        点大小=新点();
        display.getSize(大小);
        INT屏幕宽度= size.x;
        INT screenHeight = size.y;位图blurBitmap = BitmapFactory.de codeResource(getResources()
                R.drawable.invitation_blur_bg);        矩形矩形=新的Rect(0,0,blurBitmap.getWidth(),blurBitmap.getHeight());

实施要将此您的活动或片段的OnScrollListener。

  @覆盖
    公共无效onScroll(AbsListView观点,诠释firstVisibleItem,
            INT visibleItemCount,诠释totalItemCount){        的for(int i = 0; I< listview.getChildCount();我++){
            查看C = listview.getChildAt(I)            矩形R =新的矩形();
            c.getHitRect(R);            RelativeLayout的llItemBg =((RelativeLayout的)c.findViewById(列表项的R.id.root_layout);            可绘制D =新BitmapDrawable(getResources(),cropImage(R,C));            itemBackground.setBackgroundDrawable(四);        }
    }
    私人位图cropImage(矩形R,查看C2){        位图bmOverlay = Bitmap.createBitmap(屏幕宽度 - 60,
                c2.getHeight(),Bitmap.Config.ARGB_8888);
        矩形Rect1的=新的Rect(0,0,bmOverlay.getWidth(),bmOverlay.getHeight());
        涂料P =新的油漆();
        帆布C =新的Canvas(bmOverlay);
        rect.right = r.right;
        rect.top = rect.top;
        rect.bottom = r.bottom / 2;        c.drawBitmap(blurBitmap,R,Rect1的页);        返回bmOverlay;
    }

I am using LDrawer in my project. I need to make the activity which is hosting the navigation drawer darken/dim/blur when the navigation drawer is opened.

I have gone through similar questions on Stackoverflow and I have not found a satisfiying answer.

Is there any simple trick to make the activity's layout darken/dim/blur when I open my NavigationDrawer

I have the RelativeLayout of my activity defined as

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

I have the toggle 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's Layout here
                mDrawerLayout.openDrawer(mDrawerList);
            }
        }
        return super.onOptionsItemSelected(item);
    }

解决方案

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

Yes, you can simply change the background image of your activity as Blur when you open the drawer.

Other way is change the alpha or your activity simply by setalpha() and pass the value how much change you want.

If you have list control on your activity and you want to make that 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 the OnScrollListener on 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;
    }

这篇关于变暗/点心/模糊活动时的导航抽屉被打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆