码迷,mamicode.com
首页 > 其他好文 > 详细

activity 透明度更改

时间:2015-05-05 12:44:33      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:

 /**
     * 调整窗口的透明度
     * @param from>=0&&from<=1.0f
     * @param to>=0&&to<=1.0f
     * 
     * */
    private void dimBackground(final float from, final float to) {
        final Window window = getWindow();
        ValueAnimator valueAnimator = ValueAnimator.ofFloat(from, to);
        valueAnimator.setDuration(500);
        valueAnimator.addUpdateListener(new AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                WindowManager.LayoutParams params = window.getAttributes();
                params.alpha = (Float) animation.getAnimatedValue();
                window.setAttributes(params);
            }
        });

        valueAnimator.start();
    }
然后这样调用:

    /** 窗口背景变暗*/
    dimBackground(1.0f,0.5f);


    /** 窗口背景变亮*/
    dimBackground(0.5f,1.0f);


activity 透明度更改

标签:

原文地址:http://blog.csdn.net/tanranran/article/details/45499545

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!