0

Good day, apologies for the confusing title.

I am creating an android application and I need a dialog/pop up to appear at a specific X Y Position. I already have a working DialogFragmet as shown below:

public class ItemDialog extends DialogFragment implements OnClickListener{

    //a lot of public and private variables here

    public interface onSubmitListener {
        void setOnSubmitListener(String qty, String disc, String instructions, UOMClass uom);  
    }  

    @Override  
    public Dialog onCreateDialog(Bundle savedInstanceState) {  

        final Dialog dialog = new Dialog(getActivity());  
        dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,  
                WindowManager.LayoutParams.FLAG_FULLSCREEN);  

        LayoutInflater layoutInflater = (LayoutInflater) getActivity()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        View layout2 = layoutInflater.inflate(R.layout.fragment_item_dialog, null);

        dialog.setContentView(layout2);  
        setStyle(DialogFragment.STYLE_NORMAL, R.style.MyDialog);

        //snip snip more code   

        dialog.show();  

        //buttons - I set the buttons here

        //editTexts - I set the edit texts here

        //TextViews - I set the text views here

        return dialog;  
    }  

    //more functions here

}

And I call it from my base activity as follows:

ItemDialog itemDialog = new ItemDialog();

//pass values from base activity to the ItemDialog here

itemDialog.show(getFragmentManager(), "");

However, I need to be able to see the base activity and input values in the edit texts in it. As of now, my DialogFragment covers a huge part of the screen and I'm unable to see the activity behind it. Clicking outside the Dialog Fragment cancels it as well.

I've searched on how to make an alert dialog float but to no avail.

Is there a way to display a Dialog Fragment over a certain area of the screen to allow the user to see and still input values in the base activity?

Any help is very much appreciated, thank you.

Razgriz
  • 7,179
  • 17
  • 78
  • 150

1 Answers1

1

you can get window object and set it's layout parameters below code might help you.

Window window = getDialog().getWindow();

    // set "origin" to top left corner, so to speak
    window.setGravity(Gravity.TOP|Gravity.LEFT);

    // after that, setting values for x and y works "naturally"
    WindowManager.LayoutParams params = window.getAttributes();
    params.x = 300;
    params.y = 100;
    window.setAttributes(params);

for more info Position of DialogFragment in Android you can also set background color or bitmap to dialog

Community
  • 1
  • 1
mcd
  • 1,434
  • 15
  • 31
  • Thanks. I also added in `window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);`So it's more intuitive that the user can still interact with the base activity. – Razgriz Nov 29 '14 at 03:22
  • you can set your dialog at specific x and y coordinate. and set setCancelable(false). and setCanceledOnTouchOutside(false) http://developer.android.com/reference/android/app/Dialog.html#setCancelable%28boolean%29 . i am not sure it will help you or not i did't try it. – mcd Nov 29 '14 at 03:29
  • Sorry to bump this after 2 days. It seems that the DialogFragment prevents any EditTexts in the base activity to show the soft keyboard? – Razgriz Dec 01 '14 at 18:04
  • the comments here and the article->http://www.stealthcopter.com/blog/2010/01/android-blurring-and-dimming-background-windows-from-dialogs/ helped me a lot – federico verchez Oct 12 '20 at 14:53