Fondo borroso tras el diálogo

Quiero el diálogo con la pantalla borrosa debajo de él así que tomo la "captura de pantalla" de la actividad, la enmascaré y fijé como fondo de la ventana del diálogo como BitmapDrawable. Lo extraño es que el diálogo ya no está centrado en la pantalla y el diálogo táctil externo no lo descarta aunque se haya llamado a setCanceledOnTouchOutside (true).

La pregunta es: ¿por qué esto no funciona? Respectivamente, ¿cómo crear un diálogo con fondo borroso?

public class BlurDialog extends DialogFragment { public BlurDialog() { } public static BlurDialog newInstance() { return new BlurDialog(); } @Override public 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, 0, 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; } } 

Captura de pantalla

Compruebe esto: https://stackoverflow.com/a/21278278/3891036

Funciona bien para mí.

O

crear un styles.xml

 <style name="Theme.D1NoTitleDim" parent="android:style/Theme.Translucent"> <item name="android:windowNoTitle">true</item> <item name="android:windowContentOverlay">@null</item> <item name="android:backgroundDimEnabled">true</item> <item name="android:background">@android:color/transparent</item> </style> 

Y luego en su diálogo

 dialog = new Dialog(context,styles); 

Esta publicación es antigua, pero para su información:

Para crear un diálogo con fondo borroso puede utilizar esta biblioteca:

https://github.com/tvbarthel/BlurDialogFragment

Puede crear una clase que extienda BlurDialogFragment y en el método onCreateView puede inflar su diseño personalizado. Vea el siguiente ejemplo:

 public class CustomDialogFragment extends BlurDialogFragment { @Override protected 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; } @Override protected boolean isDimmingEnable() { // Enable or disable the dimming effect. // Disabled by default. return false; } @Override public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.dialog_fragment_layout, container, false); return v; } 

Para mostrar el diálogo de su Actividad:

 FragmentManager fragmentManager = getFragmentManager(); CustomDialogFragment cdf = new CustomDialogFragment(); cdf.show(fragmentManager,"yourTag"); 

  • Android DialogFragment onViewCreated no se llama
  • Cómo mostrar un menú desplegable como la cabeza de chat de libro de cara en android
  • Mostrando bloques de DialogFragments ICS
  • Estilizar texto en un DialogFragment
  • Xamarin C # Android 7.0 en Moto G5 Plus teléfono, ventana de diálogo fragmento de fondo transparente procesamiento de error
  • Barra de herramientas en DialogFragment
  • Cómo utilizar RoboDialogFragment con un diseño personalizado
  • Cómo leer / escribir las preferencias de un DialogFragment?
  • Disparar Evento táctil desde la vista DialogFragment a la vista de actividad principal
  • Cambio de la orientación del fragmento androide
  • Interceptar DialogFragment descartar dentro de la actividad
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.