J’ai besoin de créer un dialog sur un fragment (qui occupe tout l’écran). Le dialog doit être un dialog flottant qui sera positionné sur le fragment avec le fragment noirci à l’extérieur du fragment.
Pour la boîte de dialog personnalisée, j’ai un linearLayout qui a des bords incurvés, quoi que je fasse, la boîte de dialog a une bordure noire sur tous les côtés (très petite). J’ai tout essayé pour le rendre transparent et partir (pour que tout le dialog ne soit que la mise en page linéaire – boîte courbe)
Pour le DialogFragment, voici ce que j’ai pour onCreateView
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){ LinearLayout layout =(LinearLayout)inflater.inflate(R.layout.custom_dialog, null); LinearLayout item = (LinearLayout)layout.findViewById(R.id.display_item); populateItemData(item, inflater); return layout; }
custom_dialog est juste un LinearLayout qui a Android: backgroung mis à # 000000
Ceci est mon style pour la boîte de dialog personnalisée
@null true true true false @null
J’ai essayé toutes sortes de combinaisons dans ce style (d’après ce que j’ai vu en ligne) et je ne peux pas me débarrasser de cette bordure noire agaçante, je peux la peindre en blanc ou en toute autre couleur si # 000000 …
J’ai passé littéralement 3-4 heures sur ce sujet, j’espère que quelqu’un d’autre peut aider …
Essayer
getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dans DialogFragment
votre onCreateView
Essayez ceci ( Comment créer un DialogFragment 100% personnalisé ) ce travail pour le dialog
Dialog dialog = new Dialog(getActivity()); dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE); dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); // layout to display dialog.setContentView(R.layout.add_edit); // set color transpartent dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); dialog.show();
In onActivityCreated
getDialog().getWindow().getAtsortingbutes().alpha = 0.9f; // An alpha value to apply to this entire window. An alpha of 1.0 means fully opaque and 0.0 means fully transparent
pour DialogFragment
transparent
Pour une utilisation complètement transparente: setStyle (DialogFragment.STYLE_NO_FRAME, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
Pour un arrière-plan personnalisé, créez un fichier de style dans votre dossier de valeurs (values / style.xml) et utilisez-le: setStyle (DialogFragment.STYLE_NO_FRAME, yourpackagename.R.style.YOURE_CUSTOM_STYLE);
dans votre fichier de style, remplacez l’atsortingbut: android: windowBackground pour être @ color / DialogBackgroundBlackSemiTransparent
Définissez votre thème comme cela a fonctionné pour moi
Et dans votre fragment de dialog défini comme ceci
public class Progress extends DialogFragment { int style = DialogFragment.STYLE_NO_TITLE; int theme = R.style.MyDialog; public Progress() { } @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setStyle(style, theme); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.progress, container, false); } }
Ceux qui utilisent le générateur AlertDialog dans onCreateDialog
au lieu de onCreateView
peuvent atsortingbuer un thème comme le code suivant. Un ensemble complet de thèmes peut être trouvé chez R.style . N’oubliez pas que certains d’entre eux sont pris en charge récemment et ne sont pas disponibles sur les anciens téléphones.
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), android.R.style.Theme_Translucent); View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_album, null); builder.setView(view); return builder.create(); }
Essayez ceci si vous aimez:
public TransparentDialog() { super(); setStyle(STYLE_NO_FRAME, R.style.AppTheme); }
@Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setStyle(STYLE_NO_FRAME, R.style.BaseDialogTheme); }
Vous pouvez y arriver en ajoutant ceci dans Dialog Fragment ou BottomSheetDialogFragment
Dans la méthode onCreateDialog
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { Dialog dialog = super.onCreateDialog(savedInstanceState); dialog.getWindow().setGravity(Gravity.BOTTOM); dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent); dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); return dialog; }