问题是:为什么这不起作用?分别如何创建模糊背景的对话框?
public class BlurDialog extends DialogFragment {public BlurDialog() {}public static BlurDialog newInstance() { return new BlurDialog();}@OverrIDepublic Dialog onCreateDialog(Bundle savedInstanceState) { final AlertDialog alertDialog = new AlertDialog.Builder(getActivity()) .setTitle("Title") .setMessage("Message") .setPositivebutton("OK",null) .setNegativebutton("Cancel",null) .create(); alertDialog.setCanceledOntouchOutsIDe(true); VIEw vIEw = getActivity().getwindow().getDecorVIEw(); vIEw.setDrawingCacheEnabled(true); Bitmap b1 = vIEw.getDrawingCache(); Rect frame = new Rect(); getActivity().getwindow().getDecorVIEw().getwindowVisibledisplayFrame(frame); int statusbarHeight = frame.top; final int wIDth = getActivity().getwindow().getDecorVIEw().getWIDth(); final int height = getActivity().getwindow().getDecorVIEw().getHeight(); Bitmap b = Bitmap.createBitmap(b1,statusbarHeight,wIDth,height-statusbarHeight); //define this only once if blurring multiple times RenderScript rs = RenderScript.create(getActivity()); //this will blur the bitmapOriginal with a radius of 8 and save it in bitmapOriginal final Allocation input = Allocation.createFromBitmap(rs,b); //use this constructor for best performance,because it uses USAGE_SHARED mode which reuses memory final Allocation output = Allocation.createTyped(rs,input.getType()); final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs,Element.U8_4(rs)); script.seTradius(8f); script.setinput(input); script.forEach(output); output.copyTo(b); alertDialog.getwindow().setBackgroundDrawable(new BitmapDrawable(getResources(),b)); return alertDialog;}}解决方法 这篇文章很旧,但是供您参考:
要创建具有模糊背景的对话框,您可以使用此库:
https://github.com/tvbarthel/BlurDialogFragment
您可以创建一个扩展BlurDialogFragment的类,并且在onCreateVIEw方法中可以扩展自定义布局.请参阅以下示例:
public class CustomDialogFragment extends BlurDialogFragment {@OverrIDeprotected boolean isActionbarBlurred() {// Enable or disable the blur effect on the action bar.// Disabled by default.return true;} @OverrIDe protected int getBlurRadius() {// Allow to customize the blur radius factor.return 7;}@OverrIDeprotected boolean isDimmingEnable() {// Enable or disable the dimming effect.// Disabled by default.return false;}@OverrIDepublic VIEw onCreateVIEw(LayoutInflater inflater,final VIEwGroup container,Bundle savedInstanceState) {VIEw v = inflater.inflate(R.layout.dialog_fragment_layout,container,false);return v;}
要显示您的Activity中的对话框:
FragmentManager fragmentManager = getFragmentManager();CustomDialogFragment cdf = new CustomDialogFragment();cdf.show(fragmentManager,"yourTag");
`
总结以上是内存溢出为你收集整理的android – 对话框后面的模糊背景全部内容,希望文章能够帮你解决android – 对话框后面的模糊背景所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)