Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show fragment as a dialog or as a usual activity

Tags:

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?

like image 690
nixan Avatar asked Sep 29 '11 06:09

nixan


People also ask

What is a dialog fragment?

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.

How do I show fragments in activity XML?

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.

What is the difference between dialog and dialog fragment?

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.

What is fragment explain with example?

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.


1 Answers

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

like image 199
Christopher Perry Avatar answered Oct 31 '22 10:10

Christopher Perry