Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DialogFragment fill screen on phone

I am using a DialogFragment and would like to know if there is a simple way of specifying the dialog to use full screen on normal/small size device(phone). Example of what I want to achieve is confirmation/permission dialog shown on Google Play after you select to Install app.

enter image description here

like image 403
mkso Avatar asked Jul 12 '12 17:07

mkso


People also ask

How do you show DialogFragment?

Showing the DialogFragment It is not necessary to manually create a FragmentTransaction to display your DialogFragment . Instead, use the show() method to display your dialog. You can pass a reference to a FragmentManager and a String to use as a FragmentTransaction tag.

How do I close DialogFragment on Android?

tl;dr: The correct way to close a DialogFragment is to use dismiss() directly on the DialogFragment. Control of the dialog (deciding when to show, hide, dismiss it) should be done through the API here, not with direct calls on the dialog.

Is DialogFragment deprecated?

This method is deprecated. androidx. activity.

What is the difference between dialog & DialogFragment?

Dialog: A dialog is a small window that prompts the user to make a decision or enter additional information. DialogFragment: A DialogFragment is a special fragment subclass that is designed for creating and hosting dialogs.


2 Answers

If you want to fill the screen with a DialogFragment you simply can change the theme. Use for full screen android.R.style.Theme_Holo_Light and for non-fullscreen dialogs use android.R.style.Theme_Holo_Light_Dialog;

Use these values in the call to:

setStyle(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Holo_Dialog); // as an example

I call this method at the end of the onCreate().

Hope this helps Jasper

like image 77
jdekeij Avatar answered Oct 18 '22 22:10

jdekeij


In Tablet, show dialog in a normal way.

DialogFragment newFragment = MyDialogFragment.newInstance();
newFragment.show(getFragmentManager(), "dialog");

In Phone, add DialogFragment to the layout as normal fragment in Activity's onCreate().

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    if (savedInstanceState == null) {
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        DialogFragment newFragment = MyDialogFragment.newInstance();
        ft.add(R.id.embedded, newFragment);
        ft.commit();
    }

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/embedded"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

</FrameLayout>

Note: Fragment embedded by <Fragment>Tag doesn't work.

like image 42
nagoya0 Avatar answered Oct 18 '22 22:10

nagoya0