Fragment must be a public static class to be properly recreated from instance state

The error is not especially weird. If you were not getting this error before, that was weird. Android destroys and recreates fragments as part of a configuration change (e.g., screen rotation) and as part of rebuilding a task if needed (e.g., user switches to another app, your app’s process is terminated while it is in … Read more

How to create a DialogFragment without title?

Just add this line of code in your HelpDialog.onCreateView(…) getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); This way you’re explicitly asking to get a window without title 🙂 EDIT As @DataGraham and @Blundell pointed out on the comments below, it’s safer to add the request for a title-less window in the onCreateDialog() method instead of onCreateView(). This way you can prevent … Read more

DialogFragment with clear background (not dimmed)

What works for me is to adjust the WinowManager.LayoutParams in onStart() of the DialogFragment: @Override public void onStart() { super.onStart(); Window window = getDialog().getWindow(); WindowManager.LayoutParams windowParams = window.getAttributes(); windowParams.dimAmount = 0.90f; windowParams.flags |= WindowManager.LayoutParams.FLAG_DIM_BEHIND; window.setAttributes(windowParams); }

Position of DialogFragment in Android

Try something like this: @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { getDialog().getWindow().setGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP); WindowManager.LayoutParams p = getDialog().getWindow().getAttributes(); p.width = ViewGroup.LayoutParams.MATCH_PARENT; p.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE; p.x = 200; … getDialog().getWindow().setAttributes(p); … or other methods for getDialog().getWindow(). be sure to set the position after calling set-content.

How to change the background color around a DialogFragment?

I had to set android:windowIsFloating to false and android:windowBackground to my custom color in the dialog style: styles.xml <resources xmlns:android=”http://schemas.android.com/apk/res/android”> <style name=”MyDialog” parent=”@android:style/Theme.Dialog”> <item name=”android:windowFrame”>@null</item> <item name=”android:windowBackground”>@color/orange_transparent</item> <item name=”android:windowIsFloating”>false</item> <item name=”android:windowContentOverlay”>@null</item> <item name=”android:windowTitleStyle”>@null</item> <item name=”android:colorBackgroundCacheHint”>@null</item> <item name=”android:windowAnimationStyle”>@android:style/Animation.Dialog</item> <item name=”android:windowSoftInputMode”>stateUnspecified|adjustPan</item> <item name=”android:gravity”>center</item> </style> </resources> MyDialogFragment public class MyDialogFragment extends DialogFragment { @Override public void onCreate(Bundle savedInstanceState) … Read more

DialogFragment and onDismiss

Make your Activity implement OnDismissListener public final class YourActivity extends Activity implements DialogInterface.OnDismissListener { @Override public void onDismiss(final DialogInterface dialog) { //Fragment dialog had been dismissed } } DialogFragment already implements OnDismissListener, just override the method and call the Activity. public final class DialogFragmentImage extends DialogFragment { ///blah blah @Override public void onDismiss(final DialogInterface dialog) … Read more