How to Set Dialog to Show in Full Screen

Custom Dialog in full screen?

Give its constructor a non-dialog theme, such as android.R.style.Theme or android.R.style.Theme_Light.

Code by @Bob.

Dialog dialog = new Dialog(context, android.R.style.Theme_Light); 
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.MyCustomDialogLayout);
dialog.show();

How to display Dialog Fragment on FullScreen?

If you are sure that your XML's root is match_parent to match_parent, this should solve your problem, replace your onCreateDialog with below

@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
final Dialog dialog = new Dialog(getActivity());
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
return dialog;
}


@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.defeat_alert, container, false);
binding = DefeatAlertBinding.bind(view);
binding.startAgain.setOnClickListener((v -> {
mListener.onDialogPositiveClick(DefeatDialog.this);
}));
return v;
}

@Override
public void onStart() {
super.onStart();
Dialog dialog = getDialog();
if (dialog != null) {
int width = ViewGroup.LayoutParams.MATCH_PARENT;
int height = ViewGroup.LayoutParams.MATCH_PARENT;
dialog.getWindow().setLayout(width, height);
}
}

Android make a dialog appear in fullscreen

here set your screen width and width to the dialog

WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = width;
lp.height = height;
dialog.getWindow().setAttributes(lp);

or in your styles create a style like this then

 <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">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">false</item>
</style>

create a dialog object like this

dialog = new Dialog(this, R.style.DialogTheme);

Edit ::

get width and height like this for any device it will fills..

WindowManager manager = (WindowManager) getSystemService(Activity.WINDOW_SERVICE);
int width, height;
LayoutParams params;

if (Build.VERSION.SDK_INT > VERSION_CODES.FROYO) {
width = manager.getDefaultDisplay().getWidth();
height = manager.getDefaultDisplay().getHeight();
} else {
Point point = new Point();
manager.getDefaultDisplay().getSize(point);
width = point.x;
height = point.y;
}

How to make AlertDialog full screen in android

To make Alert Dialog fit screen width and height but Actionbar is visible use below code :

    void hello(){

AlertDialog.Builder builder = new AlertDialog.Builder(activity);
LayoutInflater inflater = activity.getLayoutInflater();
builder.setView(inflater.inflate(R.layout.custom_dialog_, null));
builder.setCancelable(false);
dialog = builder.show();

dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,WindowManager.LayoutParams.MATCH_PARENT);

}

And if you want to hide the Actionbar also, then first put below code in your styles.xml file

    <style name="myFullscreenAlertDialogStyle" parent="Theme.AppCompat.Light.NoActionBar">      //no actionbar, but status bar exists
<item name="android:windowFullscreen">true</item> //remove status bar
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item> //smooth animation
<item name="colorAccent">@color/colorAccent</item> //change button text color
</style>

And use this style as below:

    void hello(){

AlertDialog.Builder builder = new AlertDialog.Builder(activity,R.style.myFullscreenAlertDialogStyle);
LayoutInflater inflater = activity.getLayoutInflater();
builder.setView(inflater.inflate(R.layout.custom_dialog_, null));
builder.setCancelable(false);
dialog = builder.show();

//dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,WindowManager.LayoutParams.MATCH_PARENT);

}

How to set Full screen dialog with dialog fragment

Create a theme in your style.xml which extends from Theme.AppCompat.Light.DarkActionBar, something like below:

<style name="DialogFragmentTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>

<item name="android:paddingRight">0dp</item>
<item name="android:paddingLeft">0dp</item>
<item name="android:layout_width">match_parent</item>
<item name="android:windowNoTitle">true</item>
</style>

and set the style you created while opening the dialog, something like below:

CustomDialogFragment mDialog = new CustomDialogFragment();
...
mDialog.setStyle(DialogFragment.STYLE_NORMAL, R.style.DialogFragmentTheme);
mDialog.show(getSupportFragmentManager(), "DialogFragment");

How to make a custom alertdialog fullscreen

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)


Related Topics



Leave a reply



Submit