Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Full Screen DialogFragment in Android

People also ask

How to make full screen dialog Fragment?

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.

What is full screen fragment?

The full screen fab toggle button is placed inside a fragment which actually contains the readings. To make it dead simple: Main Activity contains Readings Fragment. Readings Fragment contains a fab button to toggle full screen.


To get DialogFragment on full screen

Override onStart of your DialogFragment like this:

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

And thanks very much to this post: The-mystery-of-androids-full-screen-dialog-fragments


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setStyle(DialogFragment.STYLE_NORMAL,
             android.R.style.Theme_Black_NoTitleBar_Fullscreen);
}

Try switching to a LinearLayout instead of RelativeLayout. I was targeting the 3.0 Honeycomb api when testing.

public class FragmentDialog extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Button button = (Button) findViewById(R.id.show);
    button.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            showDialog();
        }
    });
}

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
}

void showDialog() {
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    DialogFragment newFragment = MyDialogFragment.newInstance();
    newFragment.show(ft, "dialog");
}

public static class MyDialogFragment extends DialogFragment {

    static MyDialogFragment newInstance() {
        MyDialogFragment f = new MyDialogFragment();
        return f;
    }

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

}
}

and the layouts: fragment_dialog.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:minWidth="1000dp"  
    android:minHeight="1000dp"> 
 </LinearLayout> 

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"
    android:background="#ffffff">
    <Button android:id="@+id/show"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:text="show">
    </Button>
</LinearLayout>

Make a Full screen DialogFragment by using only the style

First solution

1. Add to your style.xml:

    <style name="FullScreenDialog" parent="Theme.AppCompat.Light.Dialog">
        <item name="android:backgroundDimEnabled">false</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:padding">0dp</item>
        <item name="android:windowIsFloating">false</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowCloseOnTouchOutside">false</item>
    </style>

2. Add to your DialogFragment:

@Override
public int getTheme() {
    return R.style.FullScreenDialog;
}

Alternative solution

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    setStyle(DialogFragment.STYLE_NO_FRAME, R.style.FullScreenDialog)
}