ActionBar in a DialogFragment

using the idea from a google group post I was able to pull it off styling an activity. you would want to modify the height and width to a “dynamic” size of your choice preferably. Then set whatever ActionBar buttons you would like <style name=”PopupTheme” parent=”android:Theme.Holo.Light.Dialog”> <item name=”android:windowIsFloating”>false</item> <item name=”android:windowContentOverlay”>@null</item> <item name=”android:windowSoftInputMode”>stateAlwaysHidden</item> <item name=”android:windowActionModeOverlay”>true</item> <item … Read more

Full Screen DialogFragment in Android

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

passing argument to DialogFragment

Using newInstance public static MyDialogFragment newInstance(int num) { MyDialogFragment f = new MyDialogFragment(); // Supply num input as an argument. Bundle args = new Bundle(); args.putInt(“num”, num); f.setArguments(args); return f; } And get the Args like this @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mNum = getArguments().getInt(“num”); … } See the full example here http://developer.android.com/reference/android/app/DialogFragment.html

How to set DialogFragment’s width and height?

If you convert directly from resources values: int width = getResources().getDimensionPixelSize(R.dimen.popup_width); int height = getResources().getDimensionPixelSize(R.dimen.popup_height); getDialog().getWindow().setLayout(width, height); Then specify match_parent in your layout for the dialog: android:layout_width=”match_parent” android:layout_height=”match_parent” You only have to worry about one place (place it in your DialogFragment#onResume). Its not perfect, but at least it works for having a RelativeLayout as the … Read more

Callback to a Fragment from a DialogFragment

Activity involved is completely unaware of the DialogFragment. Fragment class: public class MyFragment extends Fragment { int mStackLevel = 0; public static final int DIALOG_FRAGMENT = 1; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState != null) { mStackLevel = savedInstanceState.getInt(“level”); } } @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putInt(“level”, mStackLevel); } void … Read more

How to prevent a dialog from closing when a button is clicked

EDIT: This only works on API 8+ as noted by some of the comments. This is a late answer, but you can add an onShowListener to the AlertDialog where you can then override the onClickListener of the button. final AlertDialog dialog = new AlertDialog.Builder(context) .setView(v) .setTitle(R.string.my_title) .setPositiveButton(android.R.string.ok, null) //Set to null. We override the onclick … Read more

How to create a Custom Dialog box in android?

Here I have created a simple Dialog, like: custom_dialog.xml <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”fill_parent” android:layout_height=”80dp” android:background=”#3E80B4″ android:orientation=”vertical” > <TextView android:id=”@+id/txt_dia” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_gravity=”center” android:layout_margin=”10dp” android:text=”Do you realy want to exit ?” android:textColor=”@android:color/white” android:textSize=”15dp” android:textStyle=”bold”/> <LinearLayout android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_gravity=”center” android:background=”#3E80B4″ android:orientation=”horizontal” > <Button android:id=”@+id/btn_yes” android:layout_width=”100dp” android:layout_height=”30dp” android:background=”@android:color/white” android:clickable=”true” android:text=”Yes” android:textColor=”#5DBCD2″ android:textStyle=”bold” /> <Button android:id=”@+id/btn_no” android:layout_width=”100dp” … Read more