Skip to content

Instantly share code, notes, and snippets.

Created Jul 8, 2021
What would you like to do?
private fun addFloatingMenu() {
if (floatingControlView?.parent == null) {
//Set layout params to display the controls over any screen.
val params = WindowManager.LayoutParams(
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) WindowManager.LayoutParams.TYPE_PHONE else WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
params.height = dpToPx(50)
params.width = dpToPx(50)
iconWidth = params.width
iconHeight = params.height
screenHeight = windowManager?.defaultDisplay?.height?:0
screenWidth = windowManager?.defaultDisplay?.width?:0
//Initial position of the floating controls. We can customize things here
params.gravity = Gravity.TOP or Gravity.START
params.x = 0
params.y = 100
//Add the view to window manager
windowManager?.addView(floatingControlView, params)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment