1

I am opening dialog fragment. However, it does not occupy entire screen. I mean it leaves some space all side.

Below is my code :

    public class MyDialogFragment extends DialogFragment implements View.OnClickListener{
        private Context context = getActivity();

        private ImageView imageViewCancel;
        private TextView textViewTitle;
        private View view;

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            view = inflater.inflate(R.layout.layoutfile, container, false);

            getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);

            textViewTitle = (TextView) view.findViewById(R.id.textView_Screen_Title);
            setHeader("Some title");
            imageViewCancel = (ImageView) view.findViewById(R.id.imageView_Cancel);
            imageViewCancel.setOnClickListener(this);


            //to hide keyboard when showing dialog fragment
            getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

            return view;
        }

        private void setHeader(String screenTitle) {
            textViewTitle.setText(screenTitle);
        }

        @Override
        public void onClick(View view) {
            switch (view.getId()) {
                case R.id.imageView_Cancel :
                    dismiss();
                    break;
            }
        }

        @Override
        public void onStart() {
            super.onStart();
getDialog().getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
        }
    }

Refer snapshot

enter image description here

I want to open it in full screen mode so that background transparent will not be seen. Tried WindowManager.LayoutParams.MATCH_PARENT & ViewGroup.LayoutParams.MATCH_PARENT too but nothing works.

VVB
  • 7,363
  • 7
  • 49
  • 83

2 Answers2

3

Create a custom style for Dialog

<style name="CustomDialog" parent="AppTheme" >
  <item name="android:windowNoTitle">true</item>
  <item name="android:windowFullscreen">true</item>
  <item name="android:windowIsFloating">true</item>
  <item name="android:windowCloseOnTouchOutside">true</item>
</style>

then use that style in dialog fragment

@Override public void onCreate(@Nullable Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setStyle(DialogFragment.STYLE_NORMAL, R.style.CustomDialog);
}

@Override public void onStart() {
  super.onStart();
  getDialog().getWindow()
    .setLayout(WindowManager.LayoutParams.MATCH_PARENT,
        WindowManager.LayoutParams.MATCH_PARENT);
}

SampleDialogFragment sampleDialogFragment = new SampleDialogFragment();
SampleDialogFragment.show(getActivity().getSupportFragmentManager(), "sometag");
arjun
  • 3,514
  • 4
  • 27
  • 48
0

Try this: Add this in styles.xml

 <style name="MY.DIALOG" parent="android:Theme" >
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowIsFloating">false</item>
</style>

And set this style in your DialogFragment:

 @Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setStyle(DialogFragment.STYLE_NORMAL, R.style.MY_DIALOG);
}

The dialog fragment's background will appear black, change it according to your need.

Refer this post for more info: http://www.techrepublic.com/article/pro-tip-unravel-the-mystery-of-androids-full-screen-dialog-fragments/