工具提示中的底部 sheet 不起作用,此弹出窗口显示在底部 sheet 后面

Bottom sheet inside the tooltip not working , This popup is showing behind the bottom sheet

我有一个底部sheet我正在加载弹出窗口,但它没有显示在底部sheet。此弹出窗口显示在底部 sheet

后面
    CustomTextView textView = (CustomTextView) layout.findViewById(R.id.info_disc);
    textView.setText(text, TextView.BufferType.SPANNABLE);
    final PopupWindow popup = new PopupWindow(context);
    popup.setContentView(layout);
    DisplayMetrics displayMetrics = new DisplayMetrics();
    context.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    int width = displayMetrics.widthPixels;
    popup.setWidth((int) (width - (view.getX() + view.getWidth() + ViewUtils.convertDpToPixel(12, context))));
    popup.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
    popup.setFocusable(true);
    popup.setBackgroundDrawable(new BitmapDrawable());
    Rect p = locateView(view);
    popup.showAtLocation(layout, Gravity.TOP | Gravity.LEFT, p.right, p.top + 15);

这样的话,下面的sheet是一个BottomSheetDialogFragment,它控制的BottomSheetDialog确实是一个Dialog;与 Activity 的 window 完全不同的 window。 PopupWindow 与错误的 window 关联,这就是它显示在 BottomSheetDialog.

后面的原因

传递给 PopupWindowshow*() 方法的 View 用于确定将 PopupWindow 与哪个 window 相关联。在给定的片段中:

popup.showAtLocation(layout, Gravity.TOP | Gravity.LEFT, p.right, p.top + 15);

layoutView 膨胀后充当 PopupWindow 的内容,因此尚未附加到任何 window,因此它不知道在 BottomSheetDialog.

上方显示

修复方法是简单地传递 showAtLocation() 一个 View,任何 View,在调用时当前附加到 BottomSheetDialog

popup.showAtLocation(view, Gravity.TOP | Gravity.LEFT, p.right, p.top + 15);