Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Full Screen DialogFragment (over ActionBar) in Android

Im having some problems in show DialogFragment in Full Screen. In my application, i have an Fragment that when you click in some button it calls a DialogFragment. But the DialogFragment just fills the area of the Fragment (below the action bar). I would like it fills all the screen like that: http://img845.imageshack.us/img845/8682/myimage2.png

Any help?

     public class ItensActivity extends Fragment {
             ... 
            public void openDialogItens()
            {       
                dialog = new ItemDialog();      
                dialog.show(getFragmentManager(), "");
                getFragmentManager().executePendingTransactions();  

            }

            public static class ItemDialog extends DialogFragment
                {


                   @SuppressWarnings("deprecation")
                   @Override
                   public Dialog onCreateDialog(Bundle savedInstanceState) {
                      AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());        
                      builder.setView(getContentView());
                      Dialog dialog = builder.create();
                      dialog.setCanceledOnTouchOutside(true);
                      WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
                      lp.copyFrom(dialog.getWindow().getAttributes());
                      lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
                      lp.height = WindowManager.LayoutParams.FILL_PARENT;
                      dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
                      dialog.getWindow().setAttributes(lp);   
                      return dialog;
                  }

            private View getContentView() {
                   LayoutInflater inflater = getActivity().getLayoutInflater();
                   View view = inflater.inflate(R.layout.popup_item, null);
                   return view;
            }
            }    
like image 944
Jose Victor Avatar asked Apr 27 '13 15:04

Jose Victor


1 Answers

So, after search a lot, i didn't find anyway to make the DialogFragment overlays the actionbar using API 5. But i find a alternative way to do that making the Fragment calling a new activity on the screen with the theme of a dialog. This solution help me a lot, so, im sharing it here: https://stackoverflow.com/a/12275009/2327056

@StrikeForceZero 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 name="android:windowIsTranslucent">true</item>
</style>

--

public static void showAsPopup(Activity activity) {
    //To show activity as dialog and dim the background, you need to declare android:theme="@style/PopupTheme" on for the chosen activity on the manifest
    activity.requestWindowFeature(Window.FEATURE_ACTION_BAR);
    activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND,
            WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    LayoutParams params = activity.getWindow().getAttributes(); 
    params.height = 850; //fixed height
    params.width = 850; //fixed width
    params.alpha = 1.0f;
    params.dimAmount = 0.5f;
    activity.getWindow().setAttributes((android.view.WindowManager.LayoutParams) params); 
    setContentView(R.layout.activity_main);
}
like image 70
Jose Victor Avatar answered Oct 29 '22 09:10

Jose Victor