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.
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.
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.
This method is deprecated. androidx. activity.
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With