Android 底部工作表在工具提示内不工作,此弹出窗口显示在底部工作表后面

Android 底部工作表在工具提示内不工作,此弹出窗口显示在底部工作表后面,android,popup,bottom-sheet,Android,Popup,Bottom Sheet,我有一个底部表单,我正在加载弹出窗口,但它没有显示在底部表单上。此弹出窗口显示在底部工作表后面 CustomTextView textView = (CustomTextView) layout.findViewById(R.id.info_disc); textView.setText(text, TextView.BufferType.SPANNABLE); final PopupWindow popup = new PopupWindow(context);

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

    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
实际上是一个
对话框
;与
活动
窗口完全分离的窗口。
PopupWindow
与错误的窗口关联,这就是为什么它显示在
BottomSheetDialog
后面

传递给
PopupWindow
show*()
方法的
视图
用于确定与
PopupWindow
关联的窗口。在给定的代码段中:

popup.showAtLocation(layout, Gravity.TOP | Gravity.LEFT, p.right, p.top + 15);
layout
是膨胀的
视图
用作
PopupWindow
的内容,因此尚未附加到任何窗口,因此它不知道在
底部表单对话框上方显示

解决方法是在调用时,只需传递当前附加到
底部表单对话框的
showAtLocation()
a
视图
,任何
视图

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

底部工作表是
BottomSheetDialog
还是
BottomSheetDialogFragment
?这就是原因,因为这是一个与
活动
完全独立的窗口。
视图是否显示在
活动
对话框片段
的旁边?无论哪种情况,这都是您应该传递给
showAtLocation()
,而不是
layout
。我的活动是加载底部工作表,在显示弹出窗口的底部工作表中,当我调用弹出窗口时,它显示在底部工作表后面谢谢,@MikeM。这是工作,你可以把这个作为答案,我也会批准