Full Screen DialogFragment (above ActionBar) in Android

I have some problems in the full screen DialogFragment show. In my application, I have a fragment that, when you click on some button, calls DialogFragment. But DialogFragment just fills the area of ​​the fragment (below the action bar). I would like it to fill the entire screen as follows: 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; } } 
+6
source share
3 answers

So, after a lot of searching, I still didn’t find the DialogFragment overlays to display the action bar using API 5. But I find an alternative way to do this so that the Fragment triggers a new action on the screen with the theme dialog. This solution helps me a lot, so I share it here: fooobar.com/questions/119306 / ...

@StrikeForceZero, using an idea from the google group, I was able to remove it from the stylization of activities. you want to change the height and width to your preferred "dynamic" size. Then set the 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); } 
+3
source

The easiest way to find

 Dialog dialog=new Dialog(this,android.R.style.Theme_Black_NoTitleBar_Fullscreen); dialog.setContentView(R.layout.frame_help); dialog.show(); 
+1
source

You can mark your fragmet dialog to use Dialog instead of embedded snippets when calling #show.

 myDialogFragment.show(getFragmentManager(), "dialog") 

This will create a dialog that will overlap on top of the action bar and status bar (which you can manually add back if you want).

0
source

Source: https://habr.com/ru/post/943780/


All Articles