您当前的位置: 首页 > 

仙剑情缘

暂无认证

  • 1浏览

    0关注

    333博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

自定义Toast及窗口透明处理

仙剑情缘 发布时间:2018-01-28 20:27:24 ,浏览量:1

public class ToastUtils {

    public static void ToastDialog(final Activity context,int resId) {
        Toast toast = new Toast(context);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.setDuration(Toast.LENGTH_SHORT);
        View view = LayoutInflater.from(context).inflate(resId, null);
        WindowManager wm = context.getWindowManager();
        Point point = new Point();
        wm.getDefaultDisplay().getSize(point);
        int w = point.x * 3 / 4;
        toast.setView(view);
        adjustViewBrightness(view, context);
        toast.show();
    }

    public static void adjustViewBrightness(View view, final Activity context) {
        final WindowManager.LayoutParams lp = context.getWindow().getAttributes();
        lp.alpha = 0.8f;
        context.getWindow().setAttributes(lp);
        context.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

        view.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
            @Override
            public void onViewAttachedToWindow(View view) {

            }

            @Override
            public void onViewDetachedFromWindow(View view) {
                lp.alpha = 1.0f;
                context.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
                context.getWindow().setAttributes(lp);
            }
        });
    }

}
关注
打赏
1658017818
查看更多评论
立即登录/注册

微信扫码登录

0.0350s