簡體   English   中英

如何模糊對話框活動背景

[英]how to blur a dialog activity background

對不起我的英語不好 :)。 我需要模糊我的對話活動背景,我嘗試了這個方法

模糊 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

我怎樣才能解決這個問題? 或者你知道另一種模糊對話活動背景的方法嗎?

試試這個代碼片段,這將為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

首先,你不應該通過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);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM