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?
- Configurar el tamaño de un DialogFragment
- Cómo mostrar un DialogFragment de un controlador
- ¿Cómo afecta DialogFragment al ciclo de vida del Fragmento llamante?
- Deshabilitar el botón positivo / negativo en DialogFragment
- Establecer el color de la barra de estado desde DialogFragment
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; } }
- Forzar al usuario a seleccionar la opción en el diálogo
- El texto extensible no funciona en el fragmento de diálogo
- Android DialogFragment con tema de AppCompat tema
- CoordinatorLayout con CollapsingToolbarLayout rompe con el teclado en el fragmento de diálogo
- Cómo reemplazar un fragmento de diálogo de pantalla completa con otro sin mostrar la actividad de los padres?
- ¿Por qué se llama DialogFragment.onCreateView cuando se está destruyendo la actividad?
- Después de cambiar la orientación de la pantalla, el diálogo aparece aparentemente sin ninguna llamada
- ¿Cómo administrar los diálogos de pantalla completa en Android?
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");
“
- Retraso en el lanzamiento de la actividad del servicio de chat principal
- ¿Por qué se ha borrado la base de datos SQLite al borrar los datos de la aplicación de Application Management?