Search code examples
androidandroid-source

How to go about making a global bottom sheet in Android OS


I am customizing an NXP based Android 10 BSP on an iMX8 platform and I'm trying to make a custom swipe up bottom sheet that's global to the OS like the status/notifications bar on a swipe down gesture.

I've followed this thread here but customized the swipe up layout to have a list of applications available on the OS (basically a launcher within an app).
While this feature works great within my app, I actually want that slide up layout to be global so that I can launch applications no matter which card/application I'm currently on.

How would I go about doing this since this feature is limited to my main app? Would it be possible to add this to SystemUI?


Solution

  • Yes technically, you can do something like the existing NotificationBar that you can drag from the top of the screen. In your case you'd do from the bottom.

    The logic for NotificationPanelView is in SystemUI package.

    But beware, the existing logic there is a bit spaghetti code, so it could take a while to understand in order to add your own panel.


    Another option for you would be to have your panel as an overlay view on top of everything ( drawn from a background service from your app ). See this answer for some initial guidance.

    You'd show at first a transparent view, that receives all inputs. If you detect the gesture, you 'move up' the sheet from the bottom, otherwise you pass the input to apps below.

    Note that this:

    • Would mean your service needs to be a foreground service, so its not killed.
    • If your app is killed from Settings, the BottomSheet will go away as well.
    • You cannot show this over the Settings app ( intentional Android limitation)

    To recap:
    The SystemUI solution would be better long term, less limitations... but more difficult to develop initially.
    The App overlay solution is easy to implement, but has several limitations which can be a dealbreaker.