java.lang.IllegalArgumentException:Button not attached to window manager

我想实现一个悬浮窗,用这个button实现拖动效果,结果报错,请各位答疑解惑,谢谢了!


private void showFloatingWindow() {
        if (Settings.canDrawOverlays(this)) {
            LayoutInflater inflater=LayoutInflater.from(this);
            displayView=inflater.inflate(R.layout.floating_edittext, null);
            Button btn_menu_floating=displayView.findViewById(R.id.btn_menu_floating);
            btn_menu_floating.setOnTouchListener(new FloatingOnTouchListener());
            windowManager.addView(displayView, layoutParams);
        }
    }

```java
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="200dp" android:layout_height="150dp">

    <EditText
        android:id="@+id/et_floating"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="start"
        android:layout_alignParentBottom="true" />

    <Button
        android:id="@+id/btn_menu_floating"
        android:layout_width="15dp"
        android:layout_height="15dp"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:background="@drawable/btn_menu_floating"
        tools:ignore="RtlHardcoded" />

</RelativeLayout>

```

java.lang.IllegalArgumentException: View=android.widget.Button{7bb24f7 VFED..C.. ......I. 470,0-500,30 #7f070050 app:id/btn_menu_floating} not attached to window manager