android 对话框背景虚化效果,android 对话框Dialog背景虚化效果

final Dialog exitDialog = new Dialog(this, R.style.FullScreenDialog);

LinearLayout ll = (LinearLayout) inflater.inflate(

R.layout.exitdialog_layout, null);

Button submit = (Button) ll.findViewById(R.id.submit);

Button cancel = (Button) ll.findViewById(R.id.cancel);

Window w = exitDialog.getWindow();

w.setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,

WindowManager.LayoutParams.FLAG_BLUR_BEHIND);

submit.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

exitDialog.dismiss();

BaseApp.actManager.closeAllActivity();

finish();

}

});

cancel.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

exitDialog.dismiss();

}

});

exitDialog.setContentView(ll);

exitDialog.show();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以在dialog的后面造成模糊效果,模糊的实现是基于FastBlur算法实现的。项目地址:https://github.com/tvbarthel/BlurDialogFragment 效果图:使用说明:最简单的使用方式是继承BlurDialogFragment或者SupportBlurDialogFragment。如果你用的是android.app.DialogFragment,那么继承BlurDialogFragment/**  * Simple fragment with blurring effect behind.  */ public class SampleDialogFragment extends BlurDialogFragment {       @Override     public void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         this.debug(true);         this.setBlurRadius(4);         this.setDownScaleFactor(5.0f);           ...     }       ... }如果是android.support.v4.app.DialogFragment 则继承 SupportBlurDialogFragment/**  * Simple fragment with blurring effect behind.  */ public class SampleDialogFragment extends SupportBlurDialogFragment {       @Override     public void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         this.debug(true);         this.setBlurRadius(4);         this.setDownScaleFactor(5.0f);           ...     }       ... }如果你不想使用继承的方式可以直接使用BlurEngine自定义一个DialogFragment/**  * Your blur fragment directly using BlurEngine.  */ public class SampleDialogFragment extends MyCustomDialogFragment {        /**      * Engine used to blur.      */     private BlurDialogEngine mBlurEngine;       @Override     public void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);           mBlurEngine = new BlurDialogEngine(getActivity());         mBlurEngine.debug(mDebugEnable);         mBlurEngine.setBlurRadius(8);         mBlurEngine.setDownScaleFactor(8f);     }       @Override     public void onResume() {         super.onResume();         mBlurEngine.onResume(getRetainInstance());     }        @Override     public void onDismiss(DialogInterface dialog) {         super.onDismiss(dialog);         mBlurEngine.onDismiss();     }       @Override     public void onDestroy() {         super.onDestroy();         mBlurEngine.onDestroy();     }       @Override     public void onDestroyView() {         if (getDialog() != null) {             getDialog().setDismissMessage(null);         }         super.onDestroyView();     }       ... }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值