In my app I've got a fragment which is called "About". On handhelds I want this fragment to look like a usual activity but on tablets I want it to be a dialog. Which way is preferred to handle this situation?
Android DialogFragments. DialogFragment is a utility class which extends the Fragment class. It is a part of the v4 support library and is used to display an overlay modal window within an activity that floats on top of the rest of the content. Essentially a DialogFragment displays a Dialog but inside a Fragment.
You can add your fragment to the activity's view hierarchy either by defining the fragment in your activity's layout file or by defining a fragment container in your activity's layout file and then programmatically adding the fragment from within your 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.
A Fragment represents a reusable portion of your app's UI. A fragment defines and manages its own layout, has its own lifecycle, and can handle its own input events. Fragments cannot live on their own--they must be hosted by an activity or another fragment.
Make a style for this in your styles.xml
(two styles.xml files, one in the values
folder, the other in a values-large
folder) but have the style you put in the values-large folder inherit from Theme.Dialog. Then have your fragment use that style. The system will take care of the rest.
Alternatively, make your class a DialogFragment, and then either embed it into a view hierarchy, or show it as a dialog, as explained here:
http://developer.android.com/reference/android/app/DialogFragment.html#DialogOrEmbed
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