Je souhaite créer un AlertDialog
en plein écran personnalisé comme un nouvel écran d'activité.
J'ai essayé ces réponses et je ne fonctionne toujours pas
android.R.style.Theme_Black_NoTitleBar_Fullscreen ViewGroup.LayoutParams params = getDialog().getWindow().getAttributes(); params.width = WindowManager.LayoutParams.MATCH_PARENT; params.height = WindowManager.LayoutParams.MATCH_PARENT;
layout_dialogue.xml
<style name="full_screen_dialog" parent="@android:style/Theme.Dialog"> <item name="android:windowNoTitle">true</item> <item name="android:windowFullscreen">true</item> <item name="android:windowIsFloating">true</item> </style>
style.xml
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" style="@style/full_screen_dialog" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/frame"> <android.support.design.widget.FloatingActionButton android:id="@+id/closeBtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/background_sky" android:clickable="true" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent" app:srcCompat="@android:drawable/ic_delete" /> </android.support.constraint.ConstraintLayout>
J'avais aussi essayé
public void newDialog(final Context c){ final AlertDialog alertDialog; LayoutInflater layoutInflater = LayoutInflater.from(c); dialogueView = layoutInflater.inflate(R.layout.layout_dialogue, null); final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(c); alertDialogBuilder.setView(dialogueView); alertDialog = alertDialogBuilder.create(); dialogueView.findViewById((R.id.closeBtn)).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); } }); alertDialog.show(); }
Aucun d'entre eux ne fonctionne pour moi. Une suggestion sur la façon de le faire?
3 Réponses :
vous pouvez utiliser un style personnalisé, laissez-moi vous montrer un exemple
style.xml
AlertDialog.Builder builder = new AlertDialog.Builder(this , R.style.DialogTheme)
Activity.java strong>
<style name="DialogTheme" parent="android:Theme.Dialog"> <item name="android:layout_width">fill_parent</item> <item name="android:layout_height">fill_parent</item> <!-- No backgrounds, titles or window float --> <item name="android:windowBackground">@color/colorPrimary</item> <item name="android:windowNoTitle">true</item> <item name="android:windowIsFloating">false</item> </style>
Merci pour la réponse, mais comment puis-je utiliser ma mise en page personnalisée avec un bouton spécifique?
vous pouvez utiliser un exemple de mise en page personnalisée Dialog dialog = new Dialog (this, R.style.DialogTheme) dialog.setCustomLayout (R.layout.alert_Layout)
oui, c'est une manière viable. Mais, j'essaye de le faire avec alertdialog au lieu de dialog. Est-ce possible?
fonctionne mieux avec name = "android: windowIsFloating"> true. Bon et le. Merci.
Vous pouvez utiliser la méthodologie suivante. (Il est défini dans Kotlin mais vous pouvez également l'implémenter pour Java)
val fullScreenDialog = FullscreenDialog() fullScreenDialog.isCancelable = false fullScreenDialog.show(supportFragmentManager, "MyTag")
Ajoutez ce qui suit à votre styles.xml
<style name="FullScreenDialogStyle" parent="Theme.AppCompat.Dialog"> <item name="android:windowNoTitle">true</item> <item name="colorPrimaryDark">@color/appPrimaryColor</item> <item name="colorPrimary">@color/appPrimaryColor</item> <!-- Set this to true if you want Full Screen without status bar --> <item name="android:windowFullscreen">true</item> <item name="android:windowIsFloating">false</item> <!-- This is important! Don't forget to set window background --> <item name="android:windowBackground">@null</item> </style>
Ce que j'utilise pour la boîte de dialogue plein écran sans marge
new ShareImageEditorDialog().show(((FragmentActivity)activity).getSupportFragmentManager(), "MyTag");
et pour l'afficher en cliquant sur le bouton
public class ShareImageEditorDialog extends DialogFragment { @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Black_NoTitleBar_Fullscreen); } @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View v = inflater.inflate(R.layout.dialog_share_image, container); return v; } }
Je pense que selon vos besoins, vous devez utiliser Dialog au lieu de Alert Dialog. La boîte de dialogue vous permet d'utiliser votre propre vue personnalisée.
Oui, je peux y parvenir via Dialog, mais est-ce possible avec AlertDialog?