0

I want to show my dialogFragment without a title.

I start my dialog like this:

MyDialogFragment dialog = new MyDialogFragment();
dialog.show(getFragmentManager(), "dialog");

This works fine, but I have a title in my dialog.

For removing the title I tried to do this in my OnCreateView:

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

and this in my onCreate:

Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);

and this also in onCreateView and onCreate:

setStyle(DialogFragment.STYLE_NO_TITLE, 0);

But every time my window is a small, white dialog. My View is not visible, I think, it's because my dialog is too small. I found some helps, where I can set my Dialogs size, but I don't want to set a fix size. My dialog should has the size, which is really necessary to show my full view.

How can I set my dialogs size as necessary?

Or is there a solution with a alertDialog, where I can set my customView or something like this?

Thanks a lot for help! :)

user3621165
  • 212
  • 4
  • 16

2 Answers2

0

Add this in your DialogFragment. I hope this will help you:

@Override
        public void onStart() {
            super.onStart();
            if (getDialog() == null) {
                return;
            }
            DisplayMetrics metrics = new DisplayMetrics();
            getSherlockActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
            int width = metrics.widthPixels;
            int dialogWidth = width - getResources().getDimensionPixelSize(R.dimen.lef_and_right_margin);
            int dialogHeight = getResources().getDimensionPixelOffset(R.dimen.height_window);
            getDialog().getWindow().setLayout(dialogWidth, dialogHeight);
            getDialog().getWindow().setGravity(Gravity.CENTER);
        }
user3815165
  • 258
  • 2
  • 16
0

Found a solution:

I'm using a alert dialog and setting a custom view:

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setView(layout);

layout is a view, which I inflated before.

user3621165
  • 212
  • 4
  • 16