Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move a DialogFragment out of the center?

Is it possible by using a DialogFragment to be able to move it out of the center and place it anywhere on the screen?

like image 493
bardao Avatar asked May 22 '13 10:05

bardao


People also ask

How do you dismiss a DialogFragment?

tl;dr: The correct way to close a DialogFragment is to use dismiss() directly on the DialogFragment. Control of the dialog (deciding when to show, hide, dismiss it) should be done through the API here, not with direct calls on the dialog.

Is DialogFragment deprecated?

This method is deprecated. androidx.

What is the difference between dialog & DialogFragment?

Dialog: A dialog is a small window that prompts the user to make a decision or enter additional information. DialogFragment: A DialogFragment is a special fragment subclass that is designed for creating and hosting dialogs.


1 Answers

You can use

getDialog().getWindow().setAttributes(param);

in

onCreateView()

like this

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
    getDialog().getWindow().setGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP);
    WindowManager.LayoutParams param = getDialog().getWindow().getAttributes();
    param.width = LayoutParams.MATCH_PARENT;
    param.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE;
    param.x = 100;
    param.y = 100;
   .
   .
    getDialog().getWindow().setAttributes(p);
   .
   .
}
like image 119
Arun C Avatar answered Oct 10 '22 02:10

Arun C