Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a custom alertdialog fullscreen

I wish to make a custom AlertDialog full screen like a new activity screen.

Tried these answers and still not working

  • Android make a dialog appear in fullscreen
  • Make AlertDialog Custom
  • How to make an Alert dialog in full screen in Android?
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();
}

layout_dialogue.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>

style.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>

I had also tried

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;

None of them are working for me. Any suggestion on how to accomplished it?

like image 980
Tony Ming Avatar asked Dec 30 '25 04:12

Tony Ming


1 Answers

you can use custom style let me show you an example

style.xml

<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>

Activity.java

AlertDialog.Builder builder = new AlertDialog.Builder(this , R.style.DialogTheme)
like image 110
HussainAbbas Avatar answered Dec 31 '25 19:12

HussainAbbas