How to create modal dialog box in android

后端 未结 4 1265
野的像风
野的像风 2021-02-01 19:53

i want create modal dialog box for my application.

so when modal dialog box open the other activities are blocked. no event are done like back button press or home butto

4条回答
  •  没有蜡笔的小新
    2021-02-01 20:51

    Try this::

    You need to create layout that you want to show in popup. you can create layout XML and use it like this:

    LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);  
                View layout = layoutInflater.inflate(R.layout.new_popup_layout, null);  
                final PopupWindow popupWindow = new PopupWindow(
                        layout, 
                           LayoutParams.WRAP_CONTENT,  
                                 LayoutParams.WRAP_CONTENT);
    

    You can also provide click events of button like this:

    ImageButton btnChoose = (ImageButton) layout.findViewById(R.id.btnChoose);
                btnChoose.setOnClickListener(new OnClickListener()  {
    
                    @Override
                    public void onClick(View v) {
    }
    });
    

    and show this popup like this: here you want to show this on button click then button view will be there.

     popupWindow.showAtLocation(anyview,Gravity.CENTER, 0, 0);
    

提交回复
热议问题