Full Screen DialogFragment in Android
To get DialogFragment on full screen
Override onStart
of your DialogFragment like this:
@Overridepublic 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
@Overridepublic 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 {@Overrideprotected 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(); } });}@Overridepublic 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>