如何模糊对话活动背景

时间:2016-03-08 10:35:57

标签: java android layout

抱歉我的英语:)。 我需要模糊我的对话活动背景,我尝试了这个方法

  

Blur BackGround Behind AlertDialog

我用这段代码发送我的位图:

Bitmap back1 = takeScreenShot(MainActivity.this);
Bitmap back2 = fastblur(back1, 10);
Intent intent = new Intent(getApplicationContext(), FilterActivity.class);
intent.putExtra("back", back2);
startActivity(intent);

在我的活动中收到位图:

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent intent = new Intent(getIntent());
    Bitmap back = intent.getParcelableExtra("back");
    BitmapDrawable ob = new BitmapDrawable(getResources(), back);
    getWindow().setBackgroundDrawable(ob);
    setContentView(R.layout.filter_activity);
}

但是在logcat中这个错误强制关闭我:

03-08 14:03:54.685 16735-16735/ir.aftabeshafa.shafadoc E/JavaBinder: !!! FAILED BINDER TRANSACTION !!!  (parcel size = 13225428)
03-08 14:03:54.685 16735-16735/ir.aftabeshafa.shafadoc D/AndroidRuntime: Shutting down VM
03-08 14:03:54.686 16735-16735/ir.aftabeshafa.shafadoc E/AndroidRuntime: FATAL EXCEPTION: main
                                                                         Process: ir.aftabeshafa.shafadoc, PID: 16735
                                                                         java.lang.RuntimeException: Failure from system

我该如何解决这个问题?或者你知道另一种模糊对话活动背景的方法吗?

2 个答案:

答案 0 :(得分:0)

尝试使用此代码段,这将为Dialog 创建透明背景。

private void Dialog() {
        final Dialog dialog = new Dialog(GenerateToken.this);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(R.layout.customdialog_tokenvalidate);
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(false);
        Window window = dialog.getWindow();
        window.setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        window.setGravity(Gravity.CENTER);
        //The below code is EXTRA - to dim the parent view by 70%
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.dimAmount = 0.7f;
        lp.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND;
        dialog.getWindow().setBackgroundDrawable(new      ColorDrawable(android.graphics.Color.TRANSPARENT));
        dialog.getWindow().setAttributes(lp);
        //Show the dialog
        dialog.show();
        TextView tvSelectedBank = (TextView) dialog.findViewById(R.id.validatetext);
        //button for ok
        dialog.findViewById(R.id.tokenvalidate).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
                dialog.dismiss();
            }
        });
        dialog.show();
    }

如果这个答案可以帮到你,请投票。快乐的编码!。

另外,请从此帖子获取帮助Blur Background behind AlertDialog

答案 1 :(得分:0)

首先,你不应该通过Binder翻译Bitmap,binder的最大容器是1M。

你可以试试这个: 起初:

MyApplication. back2 = back2;

然后:

   @Override
protected void onCreate(Bundle savedInstanceState) {
    BitmapDrawable ob = new BitmapDrawable(getResources(),MyApplication.back2);
    getWindow().getDecorView().setBackground(ob);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.filter_activity);
}