mkso
mkso

Reputation: 3188

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

Upvotes: 6

Views: 4899

Answers (3)

Win Myo Htet
Win Myo Htet

Reputation: 5457

There has been the same question (with the exact diagram!) and answer (by the one who ask it.) The answer is a valid one too taking advantage of the resource folder categorization. Dialog fragment embedding depends on device

Upvotes: 0

jdekeij
jdekeij

Reputation: 200

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

Upvotes: 6

nagoya0
nagoya0

Reputation: 2828

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.

Upvotes: 2

Related Questions