Skip to content

Instantly share code, notes, and snippets.

@pavan5208
Created Jul 8, 2021
Embed
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(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) WindowManager.LayoutParams.TYPE_PHONE else WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT
)
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