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



我有一个底表,我正在加载弹出窗口,但它没有显示在底板上。此弹出窗口显示在底部工作表后面

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);

在这种情况下,底板是一个BottomSheetDialogFragment,它控制BottomSheetDialog确实是一个Dialog;一个与Activity窗口完全分开的窗口。PopupWindow与错误的窗口相关联,这就是为什么它显示在BottomSheetDialog后面的原因。

传递给PopupWindowshow*()方法的View用于确定与哪个窗口相关联PopupWindow。在给定的代码段中:

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

layout是膨胀的View作为PopupWindow的内容,因此还没有附加到任何窗口,所以它不知道显示在BottomSheetDialog上方。

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

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

最新更新