How can I interact with elements behind a translucent Android app?

后端 未结 3 922
星月不相逢
星月不相逢 2020-12-03 00:22

I have found how to create a translucent background for my android app, but so far I haven\'t found how to interact with what\'s behind it (the home screen for example).

3条回答
  •  情深已故
    2020-12-03 00:33

    FLAG_NOT_TOUCH_MODAL will do what you want with the least code.

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
        ...
        setContentView(R.layout.my_activity_view);
        ...
    }
    

    public static final int FLAG_NOT_TOUCH_MODAL

    Window flag: Even when this window is focusable (its {@link FLAG_NOT_FOCUSABLE is not set), allow any pointer events outside of the window to be sent to the windows behind it. Otherwise it will consume all pointer events itself, regardless of whether they are inside of the window.

提交回复
热议问题