【问题标题】:Show Dialog and still be able to do things in the Main Layout显示对话框并且仍然可以在主布局中做事
【发布时间】:2017-05-16 11:20:26
【问题描述】:

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

提前感谢您的帮助! :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));
                    }
                }
            });

【问题讨论】:

标签: android android-layout android-alertdialog


【解决方案1】:

只做一件事……

dialog.setCancelable(false);

【讨论】:

  • 请在您的回答中添加一些解释。
  • 其实先生。如果我这样做,它只会关闭对话框,但我实际上要问的是,即使对话框正在显示,我将能够操作对话框后面的所有内容先生 :D 但是感谢先生的帮助!跨度>
【解决方案2】:

我曾经做过类似的事情(或者更确切地说,我尝试过这样做。)。你看到你可以Override你的DialogdispatchTouchEvent(event)并将事件传递给你的ActivitydispatchTouchEvent(event)。虽然这确实提供了一种用户体验,我可以在 Dialog 下方的 Views 中获得触摸事件。即使我可以滚动,我也无法在ListViews 和GridViews 上获得OnItemClick() 回调。点击、滚动等在我的应用拥有的所有其他 Views 上都有效。

因此,只需在您的 Dialog 中获取对您的 Activity 的引用并传递事件。

@Override
dispatchTouchEvent(MotionEvent event) {
    activity.dispatchTouchEvent(event);
}

【讨论】:

  • 嗯,先生,我找到了解决方案,它正在使对话框成为模态。但是因为我能够在后台操作东西,所以当我移动它时地图会滞后,现在又是一个问题哈哈。但是还是感谢您的帮助先生:D
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多