2

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

Tried these answers and still not working

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?

2
  • I think as per your requirements you need to use Dialog instead of Alert Dialog. Dialog provide you to use your own custom view. Commented Feb 19, 2019 at 9:00
  • Yes, I can actually achieve it through Dialog, but can it be done using AlertDialog? Commented Feb 21, 2019 at 2:49

3 Answers 3

5

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) 
Sign up to request clarification or add additional context in comments.

5 Comments

Thank for the answer, but how can i use my custom layout with specific button?
your can use custom layout example Dialog dialog = new Dialog(this ,R.style.DialogTheme) dialog.setCustomLayout(R.layout.alert_Layout)
yep, that's a workable way. But, i am trying to do it with alertdialog instead of dialog. Is this possible?
works better with name="android:windowIsFloating">true. Good ans tho. Thanks.
This show black spots at the top and bottom of the dialog
4

You can use following methodology. (It is defined in Kotlin but you can implement for Java as well)

class FullscreenDialog: DialogFragment() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setStyle(DialogFragment.STYLE_NORMAL, R.style.FullScreenDialogStyle) } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { val view = inflater.inflate(R.layout.fragment_no_internet, container, false) return view } override fun onStart() { super.onStart() if(dialog != null) { val width = ViewGroup.LayoutParams.MATCH_PARENT val height = ViewGroup.LayoutParams.MATCH_PARENT dialog.window?.setLayout(width, height) } } } 

Add following to your 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> 

To show dialog use following:

val fullScreenDialog = FullscreenDialog() fullScreenDialog.isCancelable = false fullScreenDialog.show(supportFragmentManager, "MyTag") 

Comments

0

What i have been using for fullscreen dialog with no margin

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

and to show on button click

new ShareImageEditorDialog().show(((FragmentActivity)activity).getSupportFragmentManager(), "MyTag"); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.