Android: How to have dialogFragment to fullscreen
Asked Answered
F

10

14

Hello I have tried to override the theme to the dialogFragment for fullscreen but the full screen I wanted was an overlay on top of the previous activity so when the dialogFragment is opened, we still can see back activity from the padding between the screen and the dialogFragment.

This is the style I have used for full screen

<style name="fullscreen_dialog" parent="android:Theme" >
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowIsFloating">false</item>
</style>
Flat answered 14/10, 2015 at 0:26 Comment(1)
Possible duplicate of Full Screen DialogFragment in AndroidEventful
Z
1

You could just manually set the layout params in code like so. Hope it helps ! :). Also check it this SO Adjusting size of custom dialog box in android

Window window = myDialog.getWindow();
window.setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
Zipporah answered 14/10, 2015 at 0:37 Comment(1)
This answer uses deprecated code. Please select a different solution now. Using themes for the dialog is more accepted now.Hardfavored
S
51

This is the solution I figured out to handle your issue:

@Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        Dialog dialog = super.onCreateDialog(savedInstanceState);    
        dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        return dialog;
    }

    @Override
    public void onStart() {
        super.onStart();
        Dialog dialog = getDialog();
        if (dialog != null) {
           dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        }
    }
Sumach answered 14/10, 2015 at 5:4 Comment(0)
H
18

Below solution worked perfectly for me.

Create style for Fragment Dialog like below:

<style name="dialog_theme" parent="android:Theme" >
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">false</item>
</style>

Create your java class as below:

public class FiltersDialogFragment extends android.support.v4.app.DialogFragment {

    static FiltersDialogFragment newInstance() {
        FiltersDialogFragment fragment = new FiltersDialogFragment();
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStyle(DialogFragment.STYLE_NORMAL, R.style.dialog_theme);
    }

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

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.dialog_filters, container, false);
        return view;
    }
}

Happy coding!!!

Harim answered 17/1, 2017 at 11:6 Comment(1)
Work perfect. Nice jobHierogram
O
10

You can also do something like-

@Override
  public void onCreate(@Nullable final Bundle savedInstanceState) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      setStyle(STYLE_NO_TITLE, android.R.style.Theme_Material_Light_NoActionBar_Fullscreen);
    } else {
      setStyle(STYLE_NO_TITLE, android.R.style.Theme_DeviceDefault_Light_NoActionBar);
    }
    super.onCreate(savedInstanceState);

  }
Orland answered 14/10, 2016 at 6:23 Comment(1)
Thanks, this seemed to be the only thing that worked for me, in conjunction with the MATCH_PARENT in onStart that others have mentioned.Fruge
C
3

Below is my solution.

<style name="Dialog.App" parent="Theme.AppCompat.Dialog"></style>
<style name="Dialog.App.Fullscreen">
    <item name="android:windowActionBar">false</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:colorBackground">@null</item>
    <item name="android:colorBackgroundCacheHint">@null</item>
    <item name="android:windowFrame">@null</item>
    <item name="android:windowBackground">@null</item>

    <!--the key attribute for fullscreen dialog -->
    <item name="android:windowIsFloating">false</item>

    <!-- only width fill screen -->
    <!--<item name="android:windowMinWidthMajor">100%</item>-->
    <!--<item name="android:windowMinWidthMinor">100%</item>-->
</style>
Chaconne answered 1/11, 2018 at 2:56 Comment(0)
Z
1

You could just manually set the layout params in code like so. Hope it helps ! :). Also check it this SO Adjusting size of custom dialog box in android

Window window = myDialog.getWindow();
window.setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
Zipporah answered 14/10, 2015 at 0:37 Comment(1)
This answer uses deprecated code. Please select a different solution now. Using themes for the dialog is more accepted now.Hardfavored
G
1
    getDialog().getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    getDialog().getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
Giaour answered 4/11, 2015 at 4:29 Comment(0)
H
0

There is a method for changing the style and theme.

/* theme is optional, I am using leanback... */
setStyle(STYLE_NORMAL, R.style.AppTheme_Leanback);

I tested it to get fullscreen and its working just fine with simple layout.

Handley answered 1/9, 2016 at 18:0 Comment(0)
M
0

FWIW, I had to set up a special style that subclassed off @style/Base.Theme.AppCompat.Light. Otherwise, none of the support library fields looked right. If you use @style/Base.Theme.AppCompat.Light.Dialog, it creates that floating look which I didn't want.

Musculature answered 28/12, 2016 at 22:4 Comment(0)
S
0

I have answered this question with explanation

In this thread

Hope this helps :)

Swordtail answered 26/6, 2017 at 10:57 Comment(0)
K
0

If none of the above works (like they didn't for me), check the Android Developer Dialogs Guide for more info on how to achieve this.

public void showDialog() {
    FragmentManager fragmentManager = getSupportFragmentManager();
    CustomDialogFragment newFragment = new CustomDialogFragment();

    if (mIsLargeLayout) {
        // The device is using a large layout, so show the fragment as a dialog
        newFragment.show(fragmentManager, "dialog");
    } else {
        // The device is smaller, so show the fragment fullscreen
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        // For a little polish, specify a transition animation
        transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        // To make it fullscreen, use the 'content' root view as the container
        // for the fragment, which is always the root view for the activity
        transaction.add(android.R.id.content, newFragment)
                   .addToBackStack(null).commit();
    }
}

If, like me, your ActionBar is still showing after utilizing the above strategy, you'll need to set some flags on the UI.

private fun hideSystemUI() {
    // Enables regular immersive mode.
    // For "lean back" mode, remove SYSTEM_UI_FLAG_IMMERSIVE.
    // Or for "sticky immersive," replace it with SYSTEM_UI_FLAG_IMMERSIVE_STICKY
    window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_IMMERSIVE
            // Set the content to appear under the system bars so that the
            // content doesn't resize when the system bars hide and show.
            or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            // Hide the nav bar and status bar
            or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
            or View.SYSTEM_UI_FLAG_FULLSCREEN)
}
Kakapo answered 7/9, 2018 at 14:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.