显示对话框,仍然可以在主布局中执行操作

时间:2017-05-16 11:20:27

标签: android android-layout alertdialog android-alertdialog

我创建了一个向用户显示的悬停对话框,但我想知道是否可以显示对话框并且仍能在对话框外部执行操作?

提前感谢您的帮助! :d

这是我的MainActivity:

  mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
                @Override
                public void onMapClick(LatLng point) {
                    if(clicked)
                    {
                        List<Address> addresses = new ArrayList<>();
                        try {
                            addresses = geocoder.getFromLocation(point.latitude, point.longitude,1);
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                        android.location.Address address = addresses.get(0);
                        if (address != null) {
                            StringBuilder sb = new StringBuilder();
                            for (int i = 0; i < address.getMaxAddressLineIndex(); i++){
                                sb.append(address.getAddressLine(i) + " ");
                            }

                            dialog = new Dialog(context);
                            dialog.setContentView(R.layout.map_dialog);
                            dialog.setTitle("IS THIS YOUR LOCATION?");
                            dialog.setCancelable(true);
                            dialog.setCanceledOnTouchOutside(false);

                            text = (TextView) dialog.findViewById(R.id.textLocations);

                            text.setText(sb.toString());

                            dialog.show();

                            Window window = dialog.getWindow();
                            WindowManager.LayoutParams params = window.getAttributes();
                            params.gravity = Gravity.BOTTOM;
                             window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
                            window.setAttributes(params);
                        }
                        mMap.clear();
                        mMap.addMarker(new MarkerOptions().position(point).draggable(false));
                        mMap.moveCamera(CameraUpdateFactory.newLatLng(point));
                    }
                }
            });

2 个答案:

答案 0 :(得分:0)

只做一件事......

dialog.setCancelable(false);

答案 1 :(得分:0)

我曾经做过类似的事情(或者说我试过这样做)。您看到可以 Override Dialog dispatchTouchEvent(event)并将该活动传递给您的Activity {{1} {{ 1}}。虽然这确实提供了用户体验,但我可以在dispatchTouchEvent(event)下方的View内触摸事件。即使我可以滚动,我也无法在DialogOnItemClick()上获得ListView个回调。点击次数,滚动浏览量等适用于我的应用所拥有的所有其他GridView

因此,只需在View中获取Activity的引用并传递该事件。

Dialog